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 |
|
jsamples1277
Starting Member
1 Post |
Posted - 2012-01-26 : 09:31:45
|
| Let's say I have a table, "myTable", with columns "col_1", "col_2", "col_3", "col_4" and respective values of "year", "2010", "2011", "2012". Now I want to write a select statement that will return a particular column name depending on where a particular value is located (ie. col_1 = 'year' and '2011' in (col_2,col_3,col_4). How would I accomplish this? |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2012-01-26 : 10:49:09
|
| you mean you need to return header of column?------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2012-01-26 : 10:51:46
|
maybe this?SELECT colFROM(SELECT *FROM table tUNPIVOT(val FOR col IN (col_2,col_3,col_4))u)mWHERE val='2011'AND col_1='year' ------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
|
|
|