Regarding CASE expression in SELECT clause
What is best approach
Approach-I
SELECT
SUM(CASE WHEN CODE = 'A' THEN ISNULL(UNIT,0.00)+ISNULL(UNIT_1,0.00) END) AS UNIT_SUM
FROM tblA
Approach-II
SELECT
ISNULL(SUM(CASE WHEN CODE = 'A' THEN UNIT+UNIT_1 END),0.00) AS UNIT_SUM
FROM tblA
My concern is do I have to place
ISNULLinside the CASE expression OR outside the CASE expression. Does it affect summation of units OR both query give same result. And what happen if any UNIT column have NULL value. Does it result NULL of total.Must I use ELSE in the CASE expression as given below:
THEN ... **ELSE 0.00** END