Calculating UnitPrice Discounts

  • Can someone explain how this works.

    (isnull(([UnitPrice]*((1.0)-[UnitPriceDiscount]))*[OrderQty],(0.0)))

    If the UnitPrice is 10.00 and the OrderQty is 4 how does this equation play out?

    What is the 1.0 for ?

    thank a lot !

    Dam again!

  • The 1.0 is to implicity force the calculation to a FLOAT datatype if everything turns out to be an INTEGER. The rest is a matter of simple substitution and following algebraic hierarchy rules.

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.

    Change is inevitable... Change for the better is not.


    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)

  • Thanks,

    Is the UnitPriceDiscount a percentage or a number ?

    select 10 *((1.0)-4)* 6

    or

    select 10 *((1.0)-.25)* 6

    Dam again!

  • Looking at the formula, I don't think it is an integer. Best way to find out is look at the data in the table.

  • AFCC Inc. Com (1/29/2009)


    Thanks,

    Is the UnitPriceDiscount a percentage or a number ?

    select 10 *((1.0)-4)* 6

    or

    select 10 *((1.0)-.25)* 6

    Heh... you tell us... you're the one that can see the table. 🙂

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.

    Change is inevitable... Change for the better is not.


    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)

  • I do not have any data in the table yet.

    I see what you're saying.

    I have found some info on working with percentages from

    So what I can tell from my first question is that the [UnitPriceDiscount] is a subtraction amount from the unit price.

    --Subtract Half of the unit price from the unit price

    select cast(10.40 *((1.0)-.50)* 1 as money)

    --Add half of the unit price to the unit price

    select cast(10.40 /((1.0)-.50)* 1 as money)

    Dam again!

  • Correct... and a 30% discount rate would mean you only pay 70% of the unit price and that's the other reason for the 1... you subtract 30% (0.3) from 1 (100%) to get the 70% to pay...

    select cast(10.40 *((1.0)-.30)* 1 as money)

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.

    Change is inevitable... Change for the better is not.


    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)

  • Thanks for the help...

    Dam again!

  • You bet... thank you for the feedback.

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.

    Change is inevitable... Change for the better is not.


    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)

Viewing 9 posts - 1 through 8 (of 8 total)

You must be logged in to reply to this topic. Login to reply