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)
如果需要你得定义一个表变量
declare @tb table (..)
insert into @tb
select * from #tmpSrc
in (@unit)
不可以直接执行.
要用动态语句拼接.
select * from #tmpSrc where 1=1 and [发生时间] in (@currentMonth,@lastMonth) and [受理大单位] in(@unit)
else if len(@unit)>0
select * from #tmpSrc where 1=1 and [受理大单位] in(@unit)
else if len(@currentMonth)>5
select * from #tmpSrc where 1=1 and [发生时间] in (@currentMonth,@lastMonth)