如下:
- SQL code
declare @0 varchar(8000)select @0=''select @[email protected]+a from #tmp0 where gid=0exec('select js_no,js_yxdate,js_xlm,js_ch,js_fbtime,js_bclx [email protected]+' into #from djjj where js_hc=0 and js_xlm= case '''' when '''' then js_xlm else '''' end and js_yxdate between ''2011-11-20'' and ''2011-11-20''group by js_no,js_yxdate,js_xlm,js_ch,js_fbtime,js_bclx ')
执行后,想查询临时表#查询不到;
直接使用下列语句,则可以查询临时表#
- SQL code
select js_no,js_yxdate,js_xlm,js_ch,js_fbtime,js_bclx into #from djjj where js_hc=0 and js_xlm= case '' when '' then js_xlm else '' end and js_yxdate between '2011-11-20' and '2011-11-20'group by js_no,js_yxdate,js_xlm,js_ch,js_fbtime,js_bclx
exec 执行 select 语句,为什么查询临时表就会提示该表不存在呢?
------解决方案--------------------
呵呵,那个表在动态语句的会话里.
不在你当前的这个会话里.
改成 全局的变量就可以了.
--into ##
------解决方案--------------------
- SQL code
--给你举个例子,你一看就明白当前会话的意思了exec('create table #t(id int)')exec('select * from #t')/*invalid object name '#t'.*/exec('create table #t(id int) select * from #t')/*id-----------(0 row(s) affected)*/
------解决方案--------------------
- SQL code
declare @0 varchar(8000)select @0=''select @[email protected]+a from #tmp0 where gid=0exec('select js_no,js_yxdate,js_xlm,js_ch,js_fbtime,js_bclx [email protected]+' into #from djjj where js_hc=0 and js_xlm= case '''' when '''' then js_xlm else '''' end and js_yxdate between ''2011-11-20'' and ''2011-11-20''group by js_no,js_yxdate,js_xlm,js_ch,js_fbtime,js_bclx select * from #')
------解决方案--------------------
------解决方案--------------------