Click to See Complete Forum and Search --> : Using derived values in other calculations


crhuebner
03-16-2009, 06:41 PM
Hi, I am new to SQL and am curious about how to use derived columns in other calculations. For example I am trying to take a "Price" column from a table called "ord" and calculate sales tax and total price. I am currently using the following SQL statement, which works:

SELECT price AS Price, price*.06 AS "SalesTax", Price+(Price*.06) AS "Total Price"
[&nbsp][&nbsp]FROM ord;

I was wondering if there is a way to use the previously calculated "SalesTax" field to calculate "Total Price", instead of reusing the (Price*.06) again. What I would like to do is use (Price + SalesTax) to calculate "Total Price" instead of
(Price + Price*.06). Any help would be much appreciated. Thanks!

NogDog
03-16-2009, 10:13 PM
I'm not sure if you can or cannot, but the simpler solution might be:

SELECT price, price * .06 AS SalesTax, price * 1.06 AS TotalPrice . . .