![]() | |
![]() |
| | Thread Tools | Display Modes |
#1
| |||
| |||
|
#2
| |||
| |||
|
|
Hello, I was wondering if anyone can help me figure something out. Is it possible to do a querey in MS SQL server and have the results returned so that each result in each row is preceeded by the column name? eg. instead of usual output -> colName1, colValue1, colName2,colValue2,colName3,colValue3 ? Also I would like to only have this for certain columns ie in the above example only for columns 2 and 3 Thank you! :-) Yas |
#3
| |||
| |||
|
|
On Jun 29, 3:09 pm, Yas <yas... (AT) gmail (DOT) com> wrote: Hello, I was wondering if anyone can help me figure something out. Is it possible to do a querey in MS SQL server and have the results returned so that each result in each row is preceeded by the column name? eg. instead of usual output -> colName1, colValue1, colName2,colValue2,colName3,colValue3 ? Also I would like to only have this for certain columns ie in the above example only for columns 2 and 3 Thank you! :-) Yas Not sure what you are actually looking at |
|
create table #temp (col1 int, col2 int , col3 varchar(10)) insert into #temp values (1,10,'abcd') insert into #temp values (2,20,'efgh') select col1, ' col2:'+cast(col2 as varchar(10))+ '-col3:'+col3 as col23 from #temp drop table #temp |
#4
| |||
| |||
|
|
Now I can just do... SELECT 'FirstName', firstName, 'SecondName', secondName, 'Occupation' occupation FROM Table1 Which would output the table I want with the values between '' showing up in unnamed columns.... BUT is there a better way of doing this? |
#5
| |||
| |||
|
|
Yas (yas... (AT) gmail (DOT) com) writes: Now I can just do... SELECT 'FirstName', firstName, 'SecondName', secondName, 'Occupation' occupation FROM Table1 Which would output the table I want with the values between '' showing up in unnamed columns.... BUT is there a better way of doing this? That would indeed be the way to do it. |
![]() |
| Thread Tools | |
| Display Modes | |
| |