开发者

Row to Column in Sql [duplicate]

This question already has answers here: Closed 12 years ago.

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
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜