开发者

Row to Column in Sql [duplicate]

开发者 https://www.devze.com 2023-02-05 10:52 出处:网络
This question already has answers here: Closed 12 years ago. Possible Duplicate: How do i transform rows into columns in sql server 2005
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

精彩评论

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