全局临时表
sql='select   id,name,age   into   ##person   from   person   where   flag=1' 
Exec(@sqlstr) 
select   *   from   ##person 

解决方案 »

  1.   

    例如,如果创建名为 employees 的表,则任何人只要在数据库中有使用该表的安全权限就可以使用该表,除非它已删除。如果创建名为 #employees 的本地临时表,只有您能对该表执行操作且在断开连接时该表删除。
      

  2.   

    ##person  好象也不行哦
      

  3.   

    sql='select id,name,age into #person from person where flag=1;select * from #person' 
    Exec(@sqlstr) 
      

  4.   

    以Northwind的Orders为例declare @sql varchar(8000)
    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 行受影响)*/
      

  5.   

    临时表存在于tempdb中,由某个用户的会话创建,在该会话中,本地临时表可见
    如果创建的是全局临时表,则其他会话可见,但创建该表的会话必须没有关闭
    sql='select   id,name,age   into   #person   from   person   where   flag=1;
    select   *   from   #person ' 
    Exec(@sqlstr) 
      

  6.   

    -->EXEC外面不能访问EXEC内部生成本地临时表,但EXEC内部可以访问EXEC外部的本地临时表:
    if object_id('tempdb.dbo.#') is not null drop table #
    select * into # from sysobjects where 0=1
    exec ('insert # select * from sysobjects')
    select * from #
      

  7.   

    Limpire 
    昨夜小楼找了您很久,有事,请与我联系,谢谢!