码迷,mamicode.com
首页 > 数据库 > 详细

SQLserver简单的竖向转横向

时间:2019-08-17 20:01:43      阅读:204      评论:0      收藏:0      [点我收藏+]

标签:group by   creat   sql   table   ast   cas   lse   简单的   interface   

Declare @Sql Varchar(500)
Create Table #t(
  PatientID Varchar(20)
)
Set @Sql  = ‘‘
Select @Sql = @Sql  + ‘ Alter Table #t Add Class_‘ + Cast(Item As Varchar(20)) + ‘ Varchar(20) Default ‘‘0‘‘‘
  From YbInterface.dbo.B1
  group by Item
Print @Sql
Exec (@sql)
select * from #t
drop table #t

SQLserver简单的竖向转横向

标签:group by   creat   sql   table   ast   cas   lse   简单的   interface   

原文地址:https://www.cnblogs.com/meitai/p/11369987.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!