Calculate Costs

NotSoC#

Registered User.
Local time
Today, 16:42
Joined
Sep 19, 2001
Messages
12
I have to fields in a table:

1. Age
2. FullCost

I would like a query to work out a discount cost to meet the following criteria:

if age > 12 and Fullcost is > 100
then DiscountCost = Fullcost * 0.5

Can't seem to get this to work in SQL

Anyone got any ideas...

Thanx in advance..............Chris
 
You don't need to write the SQL. Just create a calculated column in the query. Use the IIf() function and nest one within another to test for multiple conditions. Something like:
=IIf([Age]>12,IIf([FullCost]>100,[FullCost]*.5,0),0)
That formula either evaluates to [FullCost]*.5 if both conditions are true, or to 0 otherwise.
 
SELECT AGE, IIF([AGE]>12 AND [FullCost]>100), [FullCost] * .05,[FullCost]) as FCost From MyTable

OR
SELECT AGE, FullCost from Mytable where Age < 13 OR FullCost < 101 UNION ALL SELECT AGE, FullCost * .05 from Mytable where AGE>12 AND FullCost > 100

Just off the top of my head
 
Very cool. I don't know why I never tried to string criteria along with "And" inside an IIF() function before!
 

Users who are viewing this thread

Back
Top Bottom