日期:2014-05-18  浏览次数:20486 次

以下SQL语句什么出错
declare   @ss   nvarchar(1000)
set   @ss= 'select   *     into   #t3   from   t1 '
exec   (@ss)
select   *   from     #t3

错误信息:Server:   Msg   208,   Level   16,   State   1,   Line   4
Invalid   object   name   '#t3 '.

请大侠指点!
谢谢!

因为列是动态的,我不能通过create   table   #临时表这种方式定义临时表,必须通过into   方式生成.


------解决方案--------------------
把#t3改为别的名字不用#
------解决方案--------------------
不支持臨時表的, 不信你不用臨時表試試看
因為set @ss= 'select * into #t3 from t1 '
exec (@ss)是一個會話,當它結束,臨時表也消失了
------解决方案--------------------
楼上说的对,不要用临时表
------解决方案--------------------
在存储过程后面加一句truncate table 表不就行了
------解决方案--------------------
呵,这样就行了.临时表有生存期

declare @ss nvarchar(1000)
set @ss= 'select * into #t3 from gzda select * from #t3 '
exec (@ss)
------解决方案--------------------
declare @ss nvarchar(1000)
set @ss= 'select * into #t3 from t1 '
exec (@ss)
select * from #t3
改成:

select * into #t3 from t1

select * from #t3