--1:計稅方案表
create table skm_mstr(序號 int,工資比例 int,始 int, 止 int,稅率 int,速算值 int )
/*
以下數據為深圳龍崗臺資企業計稅方式:
(比如工資為4000的計稅方式為:4000*87/100 = 3840, 在2100-3599之間,適用于第3條
則計算公式為 (4000*87/100-2100)*10/100 + 25 = 163 )
*/
insert skm_mstr select 1, 87 ,0 , 1599 , 0 ,0
union all select 2 , 87 , 1600, 2099 , 5 ,0
union all select 3 , 87 , 2100, 3599 , 10 ,25
union all select 4 , 87 , 3600, 6599 , 15 ,175
union all select 5 ,87, 6600, 99999, 20 ,625
go
--2:自定義函數計稅
create function test(@a numeric(10,2))
returns numeric(10,2)
as
begin
declare @b numeric(10,2)
select @b = ( @a * 工資比例/100 - 始) * 稅率 / 100 + 速算值
from skm_mstr
where floor(@a * 工資比例/100) between 始 and 止
return @b
end
go
--3:調用
select dbo.test(4000) -- 計算工資額為4000時的稅款。
/*顯示結果為
------------
163.00
(所影響的行數為 1 行)
*/