Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
Sathiyaseelan.ts
Starting Member
1 Post |
Posted - 2011-09-24 : 09:29:38
|
| hi all,how to get the column name for a particular column value.example:create table test(id number,col2 varchar,col3 varchar);insert into test values(1,'true','false');insert into test values(2,'false','true');commit;i want to select column name for data 'true' having id=1;i.e) i want to col2 as output;sathiyaseelan |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2011-09-24 : 09:33:34
|
one way to do it is unpivotselect columnnamefrom testunpivot(val for columnname in (col2,col3))uwhere val = 'true'and id=1 ------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
|
|
|