拼接的字符串成长动态列,通过exec把这些列查询送到临时表问题
declare @sql varchar(200)set @sql = 'select 10 as id into #t 'exec(@sql)select * from #tdrop table #t
select * from (select 10 as id)t into #t
[解决办法]
不能这样写的.
declare @sql varchar(200)create table #t(id int)set @sql = 'select 10 as id'insert into #t exec(@sql)select * from #t/*id-----------10(1 行受影响)*/drop table #t
[解决办法]
declare @sql varchar(200)create table #t(id int)set @sql = 'select 10 as id'insert into #t exec(@sql)select * from #t
[解决办法]
1楼不是写给你select ... into ...的用法了么?
--写错了,改下,汗select * into #t from (select 10 as id)t
[解决办法]
--我晕,静态的你会了,改动态的不会?declare @sql varchar(200)if object_id('#t') is not null drop table #tset @sql = 'select * into #t from (select 10 as id)t'exec(@sql)select * from #t