मैं प्रक्रिया में एक शर्त जोड़ना चाहता हूं, लेकिन मैं (IF(Wh=0,'AND 1=1','AND D.wh_parn = 102')) का उपयोग नहीं कर सकता यह मेरी प्रक्रिया है:

CREATE DEFINER=`akarremote`@`%` PROCEDURE `laporan_top_brand_penjualan`(IN Wh INT, IN `Datemin` VARCHAR(191), IN `Datemax` VARCHAR(191))
BEGIN

    SELECT
        A.item_id,
        A.item_name AS ITEM,
        (
        SELECT
            SUM( C.jumlah ) AS jumlah
        FROM
            mob_penjualan B
            LEFT JOIN mob_penjualandetail C ON C.noTransaksi = B.noTransaksi
            LEFT JOIN krd_wh D ON D.wh_id = B.idWH 
        WHERE
            C.idItemProduk = A.item_id 
            AND B.TglTransaksi BETWEEN Datemin AND Datemax
            (IF(Wh=0,'AND 1=1','AND D.wh_parn = 102'))
        GROUP BY
            C.idItemProduk 
        ORDER BY
            jumlah DESC
        ) AS JML,
        (
        SELECT
            SUM( C.qty ) AS qty
        FROM
            mob_penjualan B
            LEFT JOIN mob_penjualandetail C ON C.noTransaksi = B.noTransaksi
            LEFT JOIN krd_wh D ON D.wh_id = B.idWH 
        WHERE
            C.idItemProduk = A.item_id 
            AND B.TglTransaksi BETWEEN Datemin AND Datemax
            (IF(Wh=0,'AND 1=1','AND D.wh_parn = 102'))
        GROUP BY
            C.idItemProduk 
        ORDER BY
            qty DESC
        ) AS QTY 
    FROM
        krd_item A
    ORDER BY
        JML DESC, QTY DESC;
    
END

समाधान क्या है?

0
Dedyk Suntoro Atmojo 18 सितंबर 2020, 04:49

1 उत्तर

सबसे बढ़िया उत्तर
WHERE C.idItemProduk = A.item_id 
  AND B.TglTransaksi BETWEEN Datemin AND Datemax
  AND IF(Wh=0, 1, D.wh_parn = 102)
0
Akina 18 सितंबर 2020, 07:39