Drop Table #abcd 
if @login=true
  select * into #abcd from syspara where code='01'
else
  select * into #abcd from syspara where code='02'

解决方案 »

  1.   

    if @login=1  --true是什么? SQL中没有这个
      select * into #abcd from syspara where code='01'
    else
      select * into #abcd from syspara where code='02'
      

  2.   

    --还是错,应该是:
    select * into #abcd from syspara
    where code=case @login when 1 then '01' else '02 end
      

  3.   

    --上面写少了一个单引号
    select * into #abcd from syspara
    where code=case @login when 1 then '01' else '02' end
      

  4.   

    if object_id('temp..#abcd') is not null
    drop table #abcd 
    select * into #abcd from syspara
    where code=(case when @login=1 then '01' else '02' end)
      

  5.   

    条件判断的不是表的字段,而是存储过程中的一个变量的值
    所以以上方法都不行sqlserver为什么不让过程中出现两条活以上的创建同一个表的名字的语句呢,这几条语句是单项执行的也不行吗?根据条件可是只有一条才被执行的啊
      

  6.   

    要是这样呢
    if @login=true
      select * into #abcd from syspara where code='01'
    else
      select * into #abcd from syspara where codext='01'这句该怎么变呢?
    select * into #abcd from syspara
    where code=case @login when 1 then '01' else '02' end
      

  7.   

    if object_id('tempdb.dbo.#abcd') is not null
    drop table #abcd 
    select * into #abcd from syspara
    where code=case @login when 1 then '01' else '02' end
      

  8.   

    不知道SQL SERVER是怎么去检查语法的,select * into #abcd ...是不能写两遍,即使这样写也会报错:
    if @a>b
      select * into #abcd ...where ...
    else
      select * into #abcd ...where ...
      

  9.   

    你可以先create table #abcd(.......)
    然后再写你的语句就可以拉。if @login=true
     insert into #abcd select * from syspara where code='01'
    else
      insert into #abcd select * from syspara where code='02'