快速列转行

说明:只针对一笔记录的操作

declare @xml xml
set @xml=(select * from 表名 where 条件 for xml auto,elements XSINIL,root)
select B.v.value('local-name(.)','varchar(200)'),
   B.v.value('.','varchar(max)') from @xml.nodes('root/表名/*') B(v)

如:

declare @xml xml
set @xml=(select * from t_casedata where Id=5 for xml auto,elements XSINIL,root)
select B.v.value('local-name(.)','varchar(200)'),
   B.v.value('.','varchar(max)') from @xml.nodes('root/t_casedata/*') B(v)
 

猜你喜欢

转载自blog.csdn.net/wlzwcr/article/details/6521789