access有冇if then else ge statement??

2006-11-20 8:58 am
[Current Charges] is a calculated field. To calculate the customer’s current charges, you multiply the difference between the [Check-Out Date] and the [Check-In Date] by [Rate]. However, after further analysis, you realize that this formula must also check to see if the customer has left and arrived on the same day.
更新1:

If a customer leaves and returns later on the same day, the difference between the [Check-Out Date] and the [Check-In Date] is zero. However, the customer should still be charged for one day of parking. You decide to modify your formula to check for this situation.

更新2:

係ms access個qeury入面~究竟我應該點寫先可以做到呢個situation ar

回答 (1)

2006-11-22 4:57 am
✔ 最佳答案
Inside a calculated query field, you can use IIF() function

This is the format:
IIF(Condition, True_Result, False_Result)

So you can try this in your query field:
Current Charge:IIF(Datediff("d",[Check-In Date], [Check-Out Date])>0, Datediff("d",[Check-In Date], [Check-Out Date])*[Rate], [Rate])

This will give you your result.

You can reference this link for how to use the functions:
http://www.techonthenet.com/access/functions/date/datediff.php
http://www.techonthenet.com/access/functions/advanced/iif.php

2006-11-21 20:59:28 補充:
Correction:Current Charge:IIF(Datediff("d",[Check-In Date], [Check-Out Date])>0, Datediff("d",[Check-In Date], [Check-Out Date])*[Rate], [Rate])This is all in one line.


收錄日期: 2021-04-23 16:01:17
原文連結 [永久失效]:
https://hk.answers.yahoo.com/question/index?qid=20061120000051KK00267

檢視 Wayback Machine 備份