Can anyone tell me how to translate the following T-SQL statement:
SELECT fileld1 = CASE
WHEN T.option1 THEN -1
ELSE
CASE WHEN T.option2 THEN 0
ELSE 1
END
END
FROM Table1 AS T
The point is I need to validate two different options from the table for a single field in the select statement..
I have tried to do somthing with an IF statement in pl/sql, but it just doesnt work for me:
SELECT IF T.option1 THEN -1
ELSE IF T.option2 THEN 0
ELSE 1
END
FROM Table1 AS T
I am not actually sure how to write IF statement inside the SELECT statement..
And also, I need to do it INSIDE the select statement because I am constructing a view.
Use:
I can’t get your original TSQL to work – I get:
…because there’s no value evaluation. If you’re checking if the columns are null, you’ll need to use:
…or if you need when they are not null:
CASE expressions shortcircuit – if the first WHEN matches, it returns the value & exits handling for that row – so the options afterwards aren’t considered.