Welcome to WebmasterWorld Guest from 54.198.93.179

Forum Moderators: open

Message Too Old, No Replies

Access Query Problem

     
2:28 pm on Sep 6, 2005 (gmt 0)

10+ Year Member



I have created an query in Access combing two related tables (Rented Properties and booking dates which contains a price for any given date). I have created an extra field which finds the minimium price from the booking dates table and divides that by the property occupancy to give me a price per person.

In the expression builder I get:

MinPrice: Min(tblPrices.PriceStandard/tblProperties.PropOccupancy)

This works fine. However, some booking dates will be per person which is indicated by a yes/no box in the booking dates table. So my question is how to put a an if /else statement into the query like:

MinPrice: If tblPrices.PricePerPerson= True do this calculation else do this one.

Hope this makes sense.

TIA

4:23 pm on Sep 6, 2005 (gmt 0)

WebmasterWorld Senior Member txbakers is a WebmasterWorld Top Contributor of All Time 10+ Year Member



I'm not sure if Access supports the CASE SQL function.

The CASE function allows you to run if/then type operations in a query.

5:07 pm on Sep 6, 2005 (gmt 0)

10+ Year Member



Wingnut

You can use the IIF function in MS Access

IIf(expr, truepart, falsepart)

EG

MinPrice: IIF(tblPrices.PricePerPerson = True, CalculationForTruePart, CalculationForFalsePart)

6:05 pm on Sep 6, 2005 (gmt 0)

10+ Year Member



Thanks Graham works a treat:

The expression:

Min(IIF([tblPrices.PricePerPerson] = False,[tblPrices.PriceStandard]/[tblProperties.PropOccupancy],[tblPrices.PriceStandard]))

 

Featured Threads

Hot Threads This Week

Hot Threads This Month