Can I use a case statement as follows?
WHEN (condition1 = 1 or 2)
AND condition2 = 3
THEN result = 'Result'
Conditions 1 and 2 will be looking for different values, just fyi.
If not, is there a better way to write this?
Would this work?
CASE WHEN condition1 in (1, 2) AND condition2 = 3 THEN 'Result' ELSE NULL END AS result
Well it depends on the system you are using. For example if you use Oracle and PL/SQL you can check the statement here
What DB are you using? And do you want the statement in SQL or in some other kind of code or stored procedure?
I'm not sure what you want to do with the statement. In a
select statement, it would be:
SELECT (CASE WHEN (condition1 = 1 or 2) AND condition2 = 3 THEN 'Result' END) as result
You don't need the
NULL is returned by the statement automatically if none of the
when conditions are met.
where, it would be:
WHERE (condition1 = 1 or 2) AND (condition2 = 3) AND (result = 'Result')
else condition is equivalent to false.