不行,如果需要,你只能创建全局临时表 exec('select * into ##tmpAnalytics from #tmpSrc where 1=1 ') select * from ##tmpAnalytics 上面是可以的
exec('select * into #tmpAnalytics from #tmpSrc where 1=1;select * from #tmpAnalytics ')
if (len(@currentMonth)>5 and LEN(@unit)>0) select * into #tmpAnalytics from #tmpSrc where 1=1 and [发生时间] in (@currentMonth,@lastMonth) and [受理大单位] in(@unit) else if len(@unit)>0 select * into #tmpAnalytics from #tmpSrc where 1=1 and [受理大单位] in(@unit) else if len(@currentMonth)>5 select * into #tmpAnalytics from #tmpSrc where 1=1 and [发生时间] in (@currentMonth,@lastMonth) 这样写法的sql语句也是不行的?
exec('select * into ##tmpAnalytics from #tmpSrc where 1=1 ') select * from ##tmpAnalytics
上面是可以的
')
if (len(@currentMonth)>5 and LEN(@unit)>0)
select * into #tmpAnalytics from #tmpSrc where 1=1 and [发生时间] in (@currentMonth,@lastMonth) and [受理大单位] in(@unit)
else if len(@unit)>0
select * into #tmpAnalytics from #tmpSrc where 1=1 and [受理大单位] in(@unit)
else if len(@currentMonth)>5
select * into #tmpAnalytics from #tmpSrc where 1=1 and [发生时间] in (@currentMonth,@lastMonth) 这样写法的sql语句也是不行的?
in(@unit)
必须使用动态语句连接后处理,不能直接处理.