【叶子函数分享五十七】计算个人所得税函数 有段代码看不懂,求讲解

cjlearncsharp 2012-03-17 08:31:01
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
红色部分
...全文
107 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
  • 打赏
  • 举报
回复
sum(当什么情况满足了(也就是when后面的),然后怎么算(then后面的),不满足(else后面的),
又怎么算,有什么不懂得?)--sum我就不解释了吧,求和

34,587

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server相关内容讨论专区
社区管理员
  • 基础类社区
  • 二月十六
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧