exec 简单问题请教
如下:
declare @0 varchar(8000)select @0=''select @0=@0+a from #tmp0 where gid=0exec('select js_no,js_yxdate,js_xlm,js_ch,js_fbtime,js_bclx '+@0+' 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 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('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)*/
[解决办法]
declare @0 varchar(8000)select @0=''select @0=@0+a from #tmp0 where gid=0exec('select js_no,js_yxdate,js_xlm,js_ch,js_fbtime,js_bclx '+@0+' 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 #')
[解决办法]