【叶子函数分享五十七】计算个人所得税函数 有段代码看不懂,求讲解
create function TaxRateOfPersonal
(
@fvalue numeric(18,4)
)
returns numeric(18,4)
as
begin
declare @i numeric(18,4)
declare @basetable table(id int,
basemoney numeric(18,4),minvalue numeric(18,4),
maxvalue numeric(18,4),taxs numeric(18,4))
insert into @basetable
select 1,2000,0,1000,0.05 union all
select 2,2000,1000,3000,0.1 union all
select 3,2000,3000,6000,0.15 union all
select 4,2000,6000,10000,0.2 union all
select 5,2000,10000,15000,0.25
select @i=sum(case when @fvalue>basemoney+maxvalue
then maxvalue-minvalue else @fvalue-basemoney-minvalue end *taxs)
from @basetable where basemoney+minvalue<=@fvalue
return @i
end
红色部分
[解决办法]
sum(当什么情况满足了(也就是when后面的),然后怎么算(then后面的),不满足(else后面的),
又怎么算,有什么不懂得?)--sum我就不解释了吧,求和