在‘计算列规范’的公式中,输入以下东西会报错,为什么,[]中包含的是各个字段
([MonthlySalary]-[Medicare]-[HousingFund]-[EndowmentInsurance]-[Deduction])-2000
公式栏中,到底能写入什么样式的公式,而不报错,能写if-else吗?如果,想做选择判断,该怎么写?
比如,想实现如下功能:
if([月薪]>3000)
[个人所得税]=[月薪]*0.01-25
else if([月薪]>4000)
[个人所得税]=[月薪]*0.06-30
公式栏该怎样写?

解决方案 »

  1.   


    select [个人所得税] = (case when [月薪]>3000 then [月薪]*0.01-25 when [月薪]>4000 then [月薪]*0.06-30 end)
    from ...
      

  2.   


    验证列“ALLMonthTax”的公式时出错。
      

  3.   

    create table tb(id int,no as (case when [id]>2 then 'yes' else 'no' end))insert into tb
     select 1 union select 2 union select 3
     
     select * from tb
     
     /*
     id          no
    ----------- ----
    1           no
    2           no
    3           yes(3 行受影响)
      

  4.   

    这个表达式没什么错,可能是数据类型不对.不过即使数据类型对头,要采用类似于2楼的 case 语句来实现.
    大概是这样的意思:(case when 月薪>3000 and 月薪<=4000 then 月薪*0.01-25 when 月薪>4000 then 月薪*0.06-30 end)
      

  5.   


    [Medicare][HousingFund][EndowmentInsurance][Deduction]
    这几列也是通过[MonthlySalary]计算得来的,
    比如[Medicare]=[MonthlySalary]*0.02+3
    最后需要求出:[ALLMonthTax]=([MonthlySalary]-[Medicare]-[HousingFund]-[EndowmentInsurance]-[Deduction])-2000
    写出这么长的公式时,就报出错,难道通过[MonthlySalary]计算出那几列,不能再进行计算吗?
      

  6.   

    if 不行,case when then else end 就可以了。