Click here to Skip to main content
15,891,136 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
hi i need the sql store procedure/ function to get income tax as per following slab

Up to Rs.2,50,000	No Tax
Rs.2,50,000 - Rs.5,00,000	5%
Rs.5,00,000 - Rs.10,00,000	20%
Rs.10,00,000 and beyond	30%


What I have tried:

i have tried multiple if else but it not work
Posted
Updated 27-Aug-18 23:49pm
Comments
Er. Puneet Goel 28-Aug-18 2:44am    
Can you show us how you tried...we are happy to help you must put efforts for that first. Hope you understand.
balongi 28-Aug-18 5:07am    
declare @gross int, @rangestart int, @percantage int
set @gross =500000

select @rangestart=rangestart, @percentage =percantage from taxslab where year ='2018'

declare @taxamount int

set @taxamount =(@gross-@rangestart)*@percantage/100)
select @taxamount

but it not giving right figure as per online calcutaor of income tax site

We do not do your homework: it is set for a reason. It is there so that you think about what you have been told, and try to understand it. It is also there so that your tutor can identify areas where you are weak, and focus more attention on remedial action.

Try it yourself, you may find it is not as difficult as you think!

If you meet a specific problem, then please ask about that and we will do our best to help. But we aren't going to do it all for you!
 
Share this answer
 
Comments
balongi 28-Aug-18 5:08am    
declare @gross int, @rangestart int, @percantage int
set @gross =500000

select @rangestart=rangestart, @percentage =percantage from taxslab where year ='2018'

declare @taxamount int

set @taxamount =(@gross-@rangestart)*@percantage/100)
select @taxamount

but it not giving right figure as per online calcutaor of income tax site
OriginalGriff 28-Aug-18 5:32am    
Of course it isn't - there isn't a tax code in the world that simple!
Tax doesn't work like that: Rate A is applied for earnings from 0 to X, and Rate B is applied on earnings from X+1 to Y, then Rate C is applied on earnings form Y+1 to Z, and so on.
Then there are deductions, blah, blah, blah.

This isn't a good idea: an SP is decidedly the wrong place to do this, because rate bands and rates change too often and it is a legal requirement to get this right - the fines that are levied if you make mistakes with peoples tax are generally punitive.
Do this in your Business layer, using variable inputs from external storage - an SP is totally the wrong place to do it!
Try something like this

DECLARE @Income INT = 700000;
DECLARE @TaxPercentage INT = 0;

IF(@Income < = 250000)
	SET @TaxPercentage = 0;
ELSE IF(@Income > 250000 AND @Income <= 500000)
	SET @TaxPercentage = 5;
ELSE IF(@Income > 500000 AND @Income <= 1000000)
	SET @TaxPercentage = 20;
ELSE IF( @Income > 1000000)
	SET @TaxPercentage = 30;

SELECT @Income, @TaxPercentage
 
Share this answer
 
Comments
[no name] 28-Aug-18 6:00am    
Only a small Thing: If something is not <= 25'000 it is > 25'000 and no Need to double check this with >
balongi 28-Aug-18 6:17am    
it should give output like this

https://www.taxmann.com/Tax-Calculator.aspx
Er. Puneet Goel 28-Aug-18 6:38am    
See, we can provide you with how you can solve what you ask not what your business want. So, you need to see what logic they are implementing. Hope you understand.
Er. Puneet Goel 28-Aug-18 6:39am    
On that page, they are not just using the above formula but they have some other logic. A financial person will tell what they are doing and then you can convert them to program. That's how development works.
Richard MacCutchan 28-Aug-18 7:16am    
As 0x01AA says you do not need to double check if a value is greater than some number, when you have already checked that it is less or equal. And the last ELSE statement does not need a compare part, since it must be true if all the others are false.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900