Hi, I have a table,
tbl_A
Column1,Column2,Column3
AA 100 0
BB 100 0
CC 0 0
DD 0 100
EE 100 0
EE 0 500
In Access, I can use IIF to figure this out by using this syntax,
Column_Sum: SUM(IIF(tbl_A.Column2 <> 0 ,1, IIF(tbl_A.Column3<>0, 1, 0)))
Result:
Column1 Column_Sum
AA 1
BB 1
CC 0
DD 1
EE 2
I would like to know if I am using SQL Script in SQL Server, how can I have the same result? I tried this, but it gives me an error message:
SELECT
Column1,
SUM(Case WHEN Column2 <> 0 , Then '1')
ELSE
(Case WHEN Column3 <>0, THEN '1')
END As Column_SUM
FROM tbl_A
Can someone help?
Thank You.
tbl_A
Column1,Column2,Column3
AA 100 0
BB 100 0
CC 0 0
DD 0 100
EE 100 0
EE 0 500
In Access, I can use IIF to figure this out by using this syntax,
Column_Sum: SUM(IIF(tbl_A.Column2 <> 0 ,1, IIF(tbl_A.Column3<>0, 1, 0)))
Result:
Column1 Column_Sum
AA 1
BB 1
CC 0
DD 1
EE 2
I would like to know if I am using SQL Script in SQL Server, how can I have the same result? I tried this, but it gives me an error message:
SELECT
Column1,
SUM(Case WHEN Column2 <> 0 , Then '1')
ELSE
(Case WHEN Column3 <>0, THEN '1')
END As Column_SUM
FROM tbl_A
Can someone help?
Thank You.