jgordin
asked on
SQL select syntax with embedded logic
i need to select from two tables. both tables can be joined on id (t1.id = t2.id)
select
if t2.columnA = 1 then (
1 as abc-column-name1
t2.columnX1 as abc-column1
)
if t2.columnA = 2 then (
2 as abc-column-name2
t2.columnX2 as abc-column2
)
t1.columnA,
t2.columnB
from table1 t1, table2 t2
where t1.id = t2.id
select
if t2.columnA = 1 then (
1 as abc-column-name1
t2.columnX1 as abc-column1
)
if t2.columnA = 2 then (
2 as abc-column-name2
t2.columnX2 as abc-column2
)
t1.columnA,
t2.columnB
from table1 t1, table2 t2
where t1.id = t2.id
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Instead, manipulate only your data, for example as Patrick showed above, into fixed column names. You can then rename or hide/show these columns further down in the interface. But not directly in the query.
(°v°)