if ...
  select a,b from tb
else
  select a,b,c from tb

解决方案 »

  1.   

    select   a,b,case when 条件 then c end as c
    from   table
      

  2.   

    select a,b,c=case when 条件 then xx
                      when 条件 then xx end
    from tb
      

  3.   

    declare @sql varchar(max)
    select @sql='select a,b'+case when 条件 then ',c' else '' end+' from table'
    exec (@sql)
      

  4.   

    我的意思是,就用一个查询语句,不写声明,和函数,过程等,就一个查询语句,在select查询语句查询列之中写条件
    例:select 姓名,班级 条件 (条件成立查出 学生编号)否则不查
      

  5.   

    select   a,b,c=case   when   条件   then   xx 
                                        when   条件   then   xx   end 
    from   tb
      

  6.   

    select 姓名,班级
          ,学生编号=case 
                     when 条件成立 then 学生编号
                        else ''
                  end
    from tb
      

  7.   

    以上都不对呀,在关键字 'then' 附近有语法错误。
      

  8.   

    你条件没写对.
    请不要一尘不变地复制.select 姓名,班级
          ,学生编号=case 
                     when 分数>60 then 学生编号
                        else ''
                  end
    from tb
      

  9.   

    我条件写对着呢,我早改了,出是出来了,就是多了一列,因为是  学生编号=case ..........
    不管条件成立不成立,都会显示 学生编号列,只不过条件不成立时 学生编号列为null
    成立时有内容,但都有学生编号列.......清楚吗??
    不过,还是要谢谢你