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
原文:https://www.cnblogs.com/meitai/p/11369987.html