declare @sql nvarchar(4000)
set @sql = N'select * into #tempa from 表A'
exec (@sql)我用select * from #tempa查询出临时表中的数据,它报#tempa不存在,在字符串中定义的临时表不能在外面用吗?
set @sql = N'select * into #tempa from 表A'
exec (@sql)我用select * from #tempa查询出临时表中的数据,它报#tempa不存在,在字符串中定义的临时表不能在外面用吗?
go
insert into 表select * into 表 from 表A
select * into #tempa from 表A
--这样就既创建临时表,也导入了数据。没有什么变量与动态的SQL,不用exec也可以的
--exec (@sql)