how to reuse a CASE in the WHERE ?
- by Thibault Witzig
Hello
I'm trying to do a request that looks like this
SELECT field1, field2, field3 = CASE
WHEN field2 = 'something' THEN 'something'
WHEN field1 IS NOT NULL and field2 IS NULL THEN 'somethingElse'
ELSE NULL
END
FROM SomeTable
WHERE field3 IS NOT NULL
This results in a syntax error. I have to rewrite the CASE in the WHERE instead of just refering to it. Is there a better way to achieve this ?
And out of curiosity, why is "WHERE field3 IS NOT NULL" refused while for example "ORDER BY field3" would pass ?