有关此 JET Sql 查询的帮助
我需要帮助来执行此查询选择。
例如,我有以下字段:
- idInvoice
- 日期
- 金额
根据日期,我需要将字段“金额”乘以 x 数字或其他数字。
例如,如果日期小于 01/01/2010 则乘以 20 。但如果它是大数或等于乘以 35
Select idInvoice, date, amount, amount * varNumber from invoices
I need help to do this query select.
for example I have these fields:
- idInvoice
- date
- amount
Depending of the date I need multiply the field "amount" for x number or other one.
For example, if the date is less 01/01/2010 to multiply for 20 . But if it is major or equal to multiply for 35
Select idInvoice, date, amount, amount * varNumber from invoices
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
假设您的日期字段不允许 Null,您应该能够使用 IIf 表达式进行计算。
请注意,我将日期字段名称括在方括号中,因为日期是 Access 中的保留字。方括号向数据库引擎发出信号,表明您需要名为“date”的字段而不是 Date() 函数。
Access 日期字段还包含时间部分。因此,对于今年年初午夜之前的任何值,该查询都会将金额乘以 20。这意味着对于 2010 年 1 月 1 日凌晨 1:00,金额将乘以 30。如果这不是您想要的,请更改 IIf 表达式。
如果您的 [日期] 字段允许 Null,请查看 Access 的 Nz() 函数帮助。
Assuming your date field does not allow Nulls, you should be able to use an IIf expression for your calculation.
Notice I enclosed the date field name in square brackets because date is a reserved word in Access. The square brackets signal the database engine that you want a field named "date" rather than the Date() function.
Also Access date fields include a time component. So that query will multiple amount by 20 for any values earlier than midnight at the start of this year. That means for 1/1/2010 at 1:00 AM, amount would be multiplied by 30. If that isn't what you want, change the IIf expression.
And if your [date] field allows Nulls, look at Access' help for the Nz() function.
或者
or