if @cy_id <>'ALL'   
       begin 
 if @ordertype = 0     
                           select * into #a from ...
                   else
                           select * into #a from ...
         end
         else
         begin
 if @ordertype = 0     
                           select * into #a from ...
                   else
                           select * into #a from ...
         end

解决方案 »

  1.   

    用select * into #a from ...的时候表#a不能存在。而#a是在断开连接的时候删除。
      

  2.   

    用insert into #a from ....吧,它是用在表存在的时候
      

  3.   

    select top 0 * into #a from .....  if @cy_id <>'ALL'    
     if @ordertype = 0     
                               insert #a from ...
                       else
                               insert #a from ...
             else
     if @ordertype = 0     
                               insert #a from ...
                       else
                               insert #a from ...
      

  4.   

    先运行一下 drop table #a
    然后再建该存储过程即可。
      

  5.   

    select top 0 * into #a from .....  if @cy_id <>'ALL'    
     if @ordertype = 0     
                               insert #a select * from ...
                       else
                               insert #a select * from ...           if @ordertype = 0     
                               insert #a select * from ...
                       else
                               insert #a select * from ...
      

  6.   

    SQL是这么牛的.改一下吧.select * into #a from where 条件这里做处理.
      

  7.   

    if @cy_id <>'ALL'    
     if @ordertype = 0     
                               select * into #a from ...
                       else
                               select * into #b from ...
             else
     if @ordertype = 0     
                               select * into #c from ...
                       else
                               select * into #d from ...
    在查询的时候用:
    select * from #a
    union all select * from #b
    union all select * from #c
    union all select * from #d