Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8518721
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T06:03:43+00:00 2026-06-11T06:03:43+00:00

I have to write a calculation for the below scenario in the stored procedure

  • 0

I have to write a calculation for the below scenario in the stored procedure .I have written the below code, Please let me know if it is correct or is there any other better way to write it.

There is a NetWorth amount of some ‘x’ value and I need to calculate the commission for this ‘x’ value in the following conditions

  1. Total NetWorth up to £5,000 – 30%
  2. Total NetWorth up to £5,000.01 to £20,000 – 35%
  3. Total NetWorth up to £20,000.01 to £50,000 – 40%
  4. Total NetWorth up to £50,000.01 + – 45%

For example

If the NetWorth is 100000, the calculation goes like this

  1. For the first 5000 of 100000 the commission is 30% i.e., 5000 * 0.30 = 1500 left out(95000)
  2. For the next 20000 of 95000 the commission is 35% i.e., 20000 * 0.35 = 7000 left out(75000)
  3. For the next 50000 of 75000 the commission is 40% i.e., 50000 * 0.40 = 20000 left out(25000)
  4. For the left out 25000 the commission is 45% i,e., 25000 * 0.45 = 11250

and the total of all this commissions = point1 + point2 + point3 + point4 = 1500 + 7000 + 20000 + 11250 = 39750

Below is the code in stored procedure I have written. Please let me know if this can be improved or there is any other way to write it.

DECLARE @NetWorth DECIMAL(18, 2) 
DECLARE @InterMediateTier1Value DECIMAL(18, 2) 
DECLARE @InterMediateTier2Value DECIMAL(18, 2) 
DECLARE @InterMediateTier3Value DECIMAL(18, 2) 
DECLARE @InterMediateTier1Commission DECIMAL(18, 2) 
DECLARE @InterMediateTier2Commission DECIMAL(18, 2) 
DECLARE @InterMediateTier3Commission DECIMAL(18, 2) 
DECLARE @RemainderCommission DECIMAL(18, 2) 
DECLARE @RemainderValue DECIMAL(18, 2) 

SET @NetWorth = 40000 

DECLARE @TotalCommission DECIMAL(18, 2) 

IF @NetWorth <= 5000 
  BEGIN 
      SET @InterMediateTier1Commission = @NetWorth * 0.30 
      SET @TotalCommission = @InterMediateTier1Commission 
  END 
ELSE IF @NetWorth > 5000 
   AND @NetWorth <= 20000 
  BEGIN 
      SET @InterMediateTier2Value = @NetWorth - 5000 
      SET @InterMediateTier1Commission = 5000 * 0.30 
      SET @InterMediateTier2Commission = @InterMediateTier2Value * 0.35 
      SET @TotalCommission = @InterMediateTier1Commission 
                             + @InterMediateTier2Commission 
  END 
ELSE IF @NetWorth > 20000 
   AND @NetWorth <= 50000 
  BEGIN 
      SET @InterMediateTier1Value = @NetWorth - 5000 
      SET @InterMediateTier1Commission = 5000 * 0.30 

      IF @InterMediateTier1Value > 20000 
        SET @RemainderValue = @InterMediateTier1Value - 20000 

      SET @RemainderCommission = @RemainderValue * 0.40 
      SET @InterMediateTier2Commission = 20000 * 0.35 
      SET @TotalCommission = @InterMediateTier1Commission 
                             + @InterMediateTier2Commission 
                             + @RemainderCommission 
  END 
ELSE IF @NetWorth > 50000 
  BEGIN 
      SET @InterMediateTier1Value = @NetWorth - 5000 
      SET @InterMediateTier1Commission = 5000 * 0.30 

      IF @InterMediateTier1Value > 20000 
        SET @RemainderValue = @InterMediateTier1Value - 20000 

      SET @InterMediateTier2Commission = 20000 * 0.35 

      IF @RemainderValue > 50000 
        SET @InterMediateTier4Value = @RemainderValue - 50000 

      SET @InterMediateTier3Commission = 50000 * 0.40 
      SET @RemainderCommission = @RemainderValue * 0.45 
      SET @TotalCommission = @InterMediateTier1Commission 
                             + @InterMediateTier2Commission 
                             + @InterMediateTier3Commission 
                             + @RemainderCommission 
  END 

SELECT @TotalCommission AS TotalCommission 
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T06:03:45+00:00Added an answer on June 11, 2026 at 6:03 am

    Try this, I found it working for the below test cases

    TEST CASE 1 :DECLARE @NetWorth DECIMAL(18, 2) = 1000

    TEST CASE 2 :DECLARE @NetWorth DECIMAL(18, 2) = 9999

    TEST CASE 3: DECLARE @NetWorth DECIMAL(18, 2) = 40000

    TEST CASE 4: DECLARE @NetWorth DECIMAL(18, 2) = 78000

    Query

    DECLARE @NetWorth DECIMAL(18, 2)  = 488000  
    
    SELECT TotalCommission = 
    CONVERT(DECIMAL(18, 2),
    
        CASE WHEN @NetWorth <= 5000 THEN @NetWorth * 0.30 
                WHEN @NetWorth > 5000  AND @NetWorth <= 20000 THEN (5000 * 0.30) + (@NetWorth - 5000) * 0.35 
                WHEN @NetWorth > 20000 AND @NetWorth <= 50000 
                                    THEN CASE WHEN ((@NetWorth - 5000) > 20000)
                                                THEN (5000 * 0.30)  + 
                                                    (20000 * 0.35)  +  
                                                    ((@NetWorth - 5000)- 20000)* 0.40
                                                ELSE (5000 * 0.30)+ (20000 * 0.35)
                                            END
            WHEN @NetWorth > 50000 
                                    THEN CASE WHEN ((@NetWorth - 5000) > 20000)
                                                THEN (5000 * 0.30) +
                                                    (20000 * 0.35) + 
                                                    (50000 * 0.40) +
                                                    ((@NetWorth - 5000) - 20000 )*0.45
                                                ELSE (5000 * 0.30) + (20000 * 0.35) + (50000 * 0.40)
                                        END
    
    
        END
    )
    

    Hope this helps. Let me know if it fails in any case.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have written C++ code for performing calculations. There is a loop in the
I have written code for performing calculations. There is a loop in the code.
I have write this code but it does work only if I am already
I am not a MYSQL developer, but just had to write some code. Please
I have difficulties calculating percentage of a double value. I wrote the code below
Please look at the code below. If you look at the diagram of the
I have a loop like this: for i=1:no %some calculations fid = fopen('c:\\out.txt','wt'); %write
I have the following assignment: Write a complete 8086 program to perform the calculator
I have write my own view Bar, which extends LinearLayout . My bar has
I am trying to check if I have write access to a specific key

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.