Hi all,
I am trying to create sql that only joins to a temp table if the table exists. For example:
If parameter a = 1 the final select would be
select * from Table t
inner join Table1 t1
on t1.field = t.field
If parameter a = 2 the final select would be
select * from Table t
inner join table2 t2
on t.field = t2.field
If parameter a = 1,2 the final select would be
select * from Table t
inner join table1 t1
on t1.field = t.field
inner join table2 t2
on t2.field = t.field
The reasoning for this is because based on the parameter, different fields should be returned (thus the *), but I do not want a bunch of empty fields from a temp table that is empty. Therefore, the table is only created if it is needed. The problem is that there are numerous potential combinations, and I prefer not to do a bunch of if statements with the various combinations.
any help is greatly appreciated!
TJ
I am trying to create sql that only joins to a temp table if the table exists. For example:
If parameter a = 1 the final select would be
select * from Table t
inner join Table1 t1
on t1.field = t.field
If parameter a = 2 the final select would be
select * from Table t
inner join table2 t2
on t.field = t2.field
If parameter a = 1,2 the final select would be
select * from Table t
inner join table1 t1
on t1.field = t.field
inner join table2 t2
on t2.field = t.field
The reasoning for this is because based on the parameter, different fields should be returned (thus the *), but I do not want a bunch of empty fields from a temp table that is empty. Therefore, the table is only created if it is needed. The problem is that there are numerous potential combinations, and I prefer not to do a bunch of if statements with the various combinations.
any help is greatly appreciated!
TJ