Possible Duplicate:
How do i transform rows into columns in sql server 2005
Table name sa
Number
10
20
30
40
E开发者_运维百科xpected Result
Number Number Number Number
10 20 30 40
Try to this query
select number from sa
declare @s varchar(8000)
select @s = COALESCE(@s + ',', '') + cast(number as varchar(10)) + ' as number'
from sa
exec('select '+@s)
Select
case when 10 then 10
when 20 then 20
when 30 then 30
when 40 then 40
else
''
end
from tablenAme
精彩评论