Query syntax (1 Viewer)

yippie_ky_yay

Registered User.
Local time
Yesterday, 23:45
Joined
Jul 30, 2002
Messages
338
Hello forum,

I was wondering if you can put a little "if" statement in a querry or not?

ie say you have a single table that you are not allowed to alter which contains 2 fields - "price" and "tax". In a query we can create the "total" column like so:
SELECT tableEx.price, tableEx.tax, ([price]+[tax]) AS Total
FROM tableEx;

But say I decide that all records that have "0.00" in the tax field should have a value of "5.00" in the total, regardless of what is in the price. Could a statement like:
IF table.tax = 0.00 THEN
Total = 5.00
ELSE
Total = tableEx.price + tableEx.tax
End IF

be added somewhere?

Any help would be much appreciated!
 

Sohaila Taravati

Registered User.
Local time
Today, 04:45
Joined
Oct 24, 2001
Messages
266
This how I do it in the query:

NewTax:IIf([Tax]=0,5,[Tax])

This will look at your tax and if it equals 0, then puts 5 otherwise puts the tax. Then you can use this [NewTax]+[Price] and do your calculations in your query. I hope this helps :)
 

yippie_ky_yay

Registered User.
Local time
Yesterday, 23:45
Joined
Jul 30, 2002
Messages
338
Thank you Sohaila! This is what I was looking for.

I just have to get used to the design view I think.

Cheers!
 

Users who are viewing this thread

Top Bottom