I am trying to query for a table based on a condition. For example let's say I have table A with columns c1, c2, c3, c4, and c5.
If c5='Y' Then select c1, c2 from A else select c3, c4 from A
I am looking for something like the following:
case when c5='Y' then select c1, c2 from A else select c3, c4 from A
Any help would be appreciated.
Your case expression code doesn't make sense logically. You have to put the case expression on the row, not the table. Something like this.
select case when c5 = 'Y' then c1 else c3 end as MyFirstColumn , case when c5 = 'Y' then c2 else c4 end as MySecondColumn from A