I'm writing a sql query in an adp where a few of the columns are calculated using CASE statements.
e.g.
SELECT columnA, columnB, CASE WHEN columnC IS NULL THEN 1 ELSE 0 END BooleanColumnC, columnD
GROUP BY ......
HAVING columnA = @parameter1, BooleanColumnC = @parameter2
When I try this though I am told BooleanColumnC is an invalid column name. I've had a look around and suspect this is because I'm trying to use an alias in a HAVING clause so...
I tried putting the whole CASE statement in the HAVING clause
i.e. HAVING columnA = @parameter1, CASE WHEN columnC IS NULL THEN 1 ELSE 0 END BooleanColumnC = @parameter2 but then I get the error message "ADO Error: Incorrect Syntax near 'BooleanColumnC' "
Any ideas?
e.g.
SELECT columnA, columnB, CASE WHEN columnC IS NULL THEN 1 ELSE 0 END BooleanColumnC, columnD
GROUP BY ......
HAVING columnA = @parameter1, BooleanColumnC = @parameter2
When I try this though I am told BooleanColumnC is an invalid column name. I've had a look around and suspect this is because I'm trying to use an alias in a HAVING clause so...
I tried putting the whole CASE statement in the HAVING clause
i.e. HAVING columnA = @parameter1, CASE WHEN columnC IS NULL THEN 1 ELSE 0 END BooleanColumnC = @parameter2 but then I get the error message "ADO Error: Incorrect Syntax near 'BooleanColumnC' "
Any ideas?