select (sum(case pdapaytype when 1 then pdaaccount_price else 0 end)- sum(pdaaccount_priceback))  as cash
  from pdaaccount 我想得出cash的值如果为空,为默认为0.00,非空的话格式化为两位小数,谢谢!

解决方案 »

  1.   

    select convert(decimal(20, 2), isnull((sum(case pdapaytype when 1 then pdaaccount_price else 0 end)- sum(pdaaccount_priceback)),0)  as cash 
      from pdaaccount 
      

  2.   

    select 
      cast((sum(case pdapaytype when 1 then pdaaccount_price else 0 end)- isnull(sum(pdaaccount_priceback),0)) as dec(18,2))  as cash 
    from pdaaccount 
      

  3.   

    少写了一个括号
    select convert(decimal(20, 2), isnull((sum(case pdapaytype when 1 then pdaaccount_price else 0 end)- sum(pdaaccount_priceback)),0))  as cash 
      from pdaaccount 
      

  4.   

    select convert(decimal(10,2), sum(case pdapaytype when 1 then pdaaccount_price else 0 end - pdaaccount_priceback))  as cash 
    from pdaaccount 
      

  5.   

    cast(),convert()函數都可以的.樓主自己看一下這兩個函數的用法吧.那樣你會進步的更快.