-- =============================================
-- Author: Maco_wang
-- Create date: 2011-03-<Create Date,,>
-- Description: 参考htl258(Tony)的思路,改写的计算个税的函数
-- =============================================
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
--测试示例
select dbo.TaxRateOfPersonal(2500)
select dbo.TaxRateOfPersonal(3500)
select dbo.TaxRateOfPersonal(5000)
select dbo.TaxRateOfPersonal(9500)
--运行结果
/*
25.0000
100.0000
250.0000
1000.0000
*/