Subject | Trick to use CASE WHEN to return two results |
---|---|
Author | kokok_kokok |
Post date | 2012-07-30T12:20:26Z |
I have the typical structure
SELECT
CASE
WHEN <expr1> THEN val1
WHEN <expr2> THEN val2
...
END
FROM MY TABLE
Is there a way or "trick" to return 2 values or columns in the same CASE
statement?
Now I need to repeat the CASE...END statements for the second column, using the
same <expr> but changing only the <val>. It is a pain because the <expr> are
really long (several lines) and the SQL statement is more unreadable.
Thank you
SELECT
CASE
WHEN <expr1> THEN val1
WHEN <expr2> THEN val2
...
END
FROM MY TABLE
Is there a way or "trick" to return 2 values or columns in the same CASE
statement?
Now I need to repeat the CASE...END statements for the second column, using the
same <expr> but changing only the <val>. It is a pain because the <expr> are
really long (several lines) and the SQL statement is more unreadable.
Thank you