从表的第一行到单列--Sql Query

时间:2011-08-02 06:22:18

标签: sql

请查看下表,

RowID  Name    Age
1      Karhik  26

我希望结果格式低于

Column1
1
Karthik
26

1 个答案:

答案 0 :(得分:2)

DECLARE @Table table( RowID  int, Name varchar(10), Age int )
insert into @table
select 1,'Karhik',26
--Show original row
select * from @table
--Unpivot Row
select Value
from
(select cast(rowid as varchar(10)) as rowid, name, cast(age as varchar(10) )as age from @table) as x
UNPIVOT
   (Value FOR [Column] IN 
      (rowid, name, age)
)AS unpvt