exec('select * into #tmpAnalytics from #tmpSrc where 1=1 ')

select * from #tmpAnalytics
这样不能用吗?

解决方案 »

  1.   

    不行,如果需要,你只能创建全局临时表
    exec('select * into ##tmpAnalytics from #tmpSrc where 1=1 ') select * from ##tmpAnalytics
    上面是可以的
      

  2.   

    exec('select * into #tmpAnalytics from #tmpSrc where 1=1;select * from #tmpAnalytics
     ') 
      

  3.   


    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语句也是不行的?
      

  4.   

    这个:
    in(@unit)
    必须使用动态语句连接后处理,不能直接处理.