Hi. i want to sum the iif value and i dont know the right way to do that.
i attached the sample data in sum iif(zip file) please help me solve this problem.
i attached the sample data in sum iif(zip file) please help me solve this problem.
SELECT SUM(CASE
WHEN [DanielProd] = 'GAS' THEN [T_OAmt]
ELSE 0
END) AS [GasTotal]
, SUM(CASE
WHEN [DanielProd] = 'LIQUID' THEN [T_OAmt]
ELSE 0
END) AS [LiqTotal]
, SUM(CASE
WHEN [DanielProd] = 'OIL' THEN [T_OAmt]
ELSE 0
END) AS [OilTotal]
, SUM(CASE
WHEN [DanielProd] = 'OTH' THEN [T_OAmt]
ELSE 0
END) AS [OthTotal]
FROM [YourTable]
WHERE [Month] = @Month
AND [Year] = @Year
Comment