全局临时表
sql='select id,name,age into ##person from person where flag=1'
Exec(@sqlstr)
select * from ##person
sql='select id,name,age into ##person from person where flag=1'
Exec(@sqlstr)
select * from ##person
Exec(@sqlstr)
set @sql='select OrderID,EmployeeID into #person from Orders where EmployeeID=5;select * from #person'
Exec(@sql) /*
OrderID EmployeeID
----------- -----------
10248 5
10254 5
10269 5
10297 5
10320 5
10333 5
10358 5
10359 5
10372 5
10378 5
10397 5
10463 5
10474 5
10477 5
10529 5
10549 5
10569 5
10575 5
10607 5
10648 5
10649 5
10650 5
10654 5
10675 5
10711 5
10714 5
10721 5
10730 5
10761 5
10812 5
10823 5
10841 5
10851 5
10866 5
10869 5
10870 5
10872 5
10874 5
10899 5
10922 5
10954 5
11043 5(42 行受影响)*/
如果创建的是全局临时表,则其他会话可见,但创建该表的会话必须没有关闭
sql='select id,name,age into #person from person where flag=1;
select * from #person '
Exec(@sqlstr)
if object_id('tempdb.dbo.#') is not null drop table #
select * into # from sysobjects where 0=1
exec ('insert # select * from sysobjects')
select * from #
昨夜小楼找了您很久,有事,请与我联系,谢谢!