I have a table lets say
Table1
t_id A B C
100 1 1 0
101 1 0 1
102 1 1 0
Now I have input parameter param0 based on which first I have to select column (lets say B) and then using t_id value(lets say 101) i will be selecting value of that selected column(which is 0).
I want to create single query as i will be using it in join query.
Is above possible, if yes how to write the sql for same?
In MySQL, this is most easily done with a case
statement:
select (case when @param0 = 'A' then A
when @param0 = 'B' then B
when @param0 = 'C' then C
end) as val
from table t
where id = @t_id;
Actually, it is most easily done with a case statement in almost any database.
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments