写一个存储过程,需要判断几个字段,比如我要对比一个表里的费用合计、本月结余、是否已付款,未付款用户的本月结余是空的,但是我要判断,如果他的费用合计小于本月结余,就要在余额里面显示负数,这个该如何实现,请哪位大侠帮忙

解决方案 »

  1.   

    select case when 费用合计<本月结余 then -余额 end from tb 
      

  2.   

    select case when 条件 then
                when 条件 then
                else XXX
           END
    FROM tb
    ------------IF 条件
        select ...
    ELSE IF 条件
        SELECT ...
       
      

  3.   

    case when 他的费用合计<本月结余 then -余额 else 余额 end
      

  4.   

    select只能用case when语句,另外流程控制不能用case when,可以用if else
      

  5.   

    不能用if else 但是可以用case when 。
      

  6.   

    建议你查查SQL联机丛书,或者到MSDN上查一下也可以,这都是比较基础的,MSDN上有例句。
    select case
    http://msdn.microsoft.com/zh-cn/library/ms181765.aspxif else
    http://msdn.microsoft.com/zh-cn/library/aa258850(v=SQL.80).aspx
      

  7.   

    select case when 本月结余=0 or 本月结余 is null then 0 when 本月结余!=0 and 费用合计<本月结余 then -余额 end as 余额 from tb
      

  8.   

    case when XXX then  XXX
         when XXX then  XXX
         when XXX then  XXX
         else XXX end      
      

  9.   

    可以放在存储过程里面用if else
      

  10.   

    语句用case when 存储过程用if else
      

  11.   

    select case when 条件 then 结果 else 结果 end ,* from 表名 where 条件if 条件
    begin
    结果
    end 
    else
    begin
    结果
    end