[Leaf function sharing] Calculate personal income tax function

Source: Internet
Author: User

-- ===================================================== ======

-- Author: maco_wang

-- Create Date: 2011-03-<create date,>

-- Description: refer to the htl258 (Tony) idea to rewrite the function for calculating the tax.

-- ===================================================== ======

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 0.05, Union all

Select 0.1, Union all

Select 0.15, Union all

Select 0.2, Union all

Select 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

 

-- Test example

Select DBO. taxrateofpersonal (2500)

Select DBO. taxrateofpersonal (3500)

Select DBO. taxrateofpersonal (5000)

Select DBO. taxrateofpersonal (9500)

 

-- Running result

/*

25.0000

100.0000

250.0000

1000.0000

*/

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.