我现在要把两个字段相除后输出,总写不对,麻烦各位朋友指点指点。
主要是计算:
结算比例=已收金额/金额
当金额为0时,不进行计算结算的比例,或则让结算比例为0。
谢谢了啊

解决方案 »

  1.   

    update tab
    set 结算比例=case when 金额=0 then 0 else 已收金额/金额 end
    where ...
      

  2.   

    结算比例=case when 金额 = 0 then 0 else 已收金额/金额 end 
    -- the yang ?
      

  3.   

    declare @已收金额 decimal(18,2),@金额 decimal(18,2)
    set @已收金额=30
    set @金额=100
    select ltrim(cast(@已收金额*100.0/@金额 as decimal(18,2)))+'%'30%
      

  4.   

    要选择?
    select 结算比例=case when 金额=0 then 0 else 已收金额/金额 end
    from tab