Say I have columns is_return_foo
, is_return_bar
and is_return_baz
.
I need to return the foo, bar, baz columns if any of the above are respectively set to true...
Is CASE WHEN
the best option?
Something like:
SELECT
CASE is_return_foo WHEN true THEN foo ELSE null
CASE is_return_bar WHEN true THEN bar ELSE null
CASE is_return_baz WHEN true THEN baz ELSE null
another_column
FROM
my_table
Update
Basically I want to return columns based on on/off flags. So if flag A is on then return the column A value, if flag B is on then return column B value.
Maybe we could say based on permissions but more fine grained.
So say you have email message with to, from, body, headers, read, read time.
So a standard user will only see to from, body, and a premium customer might be configured to also read headers, read and read time.
But would.like to do ot per column instead of group of columns.
If it was group of columns then we could easily say CASE WHEN premium THEN headers, read, read time.
Update 2
I think we can do group based "permissions" so if you are a silver member you only see some fields, but if you are gold member you see all fields.