create table t
(Name varchar(2),Result varchar(3))insert t
select 'a','R1' union all
select 'b','R2' union all
select 'c','R3' union all
select 'd','R4'declare @sql varchar(2000)
set @sql=''
select @sql=@sql+','+name+' varchar(20),'+Result+' varchar(20)'
from t
set @sql='create table t_temp('+stuff(@sql,1,1,'')+')'
exec(@sql)
select * from t_tempdrop table t_temp
drop table t
a R1 b R2 c R3 d R4
-------------------- -------------------- -------------------- -------------------- -------------------- -------------------- -------------------- -------------------- (所影响的行数为 0 行)
(Name varchar(2),Result varchar(3))insert t
select 'a','R1' union all
select 'b','R2' union all
select 'c','R3' union all
select 'd','R4'declare @sql varchar(2000)
set @sql=''
select @sql=@sql+','+name+' varchar(20),'+Result+' varchar(20)'
from t
set @sql='create table t_temp('+stuff(@sql,1,1,'')+')'
exec(@sql)
select * from t_tempdrop table t_temp
drop table t
a R1 b R2 c R3 d R4
-------------------- -------------------- -------------------- -------------------- -------------------- -------------------- -------------------- -------------------- (所影响的行数为 0 行)
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货