首页 > 解决方案 > 如何连接日期变量以在 where 条件之间创建

问题描述

当我试图将我的值设置为用户给定的查询开始日期和结束日期之间时,我遇到了运行时错误 3071(表达式输入错误或太复杂)

这用于将用户给定的变量从表单传递到查询

请看下面

WHERE (
IIf([Forms]![Find]![Entity]<>"",DB.Entity=[Forms]![Find]![Entity],"*")
AND IIf([Forms]![Find]![AEPS]<>"",DB.AEPSProgram=[Forms]![Find]![AEPS],"*")
AND IIf([Forms]![Find]![DeliveryType]<>"",DB.DeliveryType=[Forms]![Find]![DeliveryType],"*")
AND IIf([Forms]![Find]![ReportingYear] is not Null,DB.ReportingYear=[Forms]![Find]![ReportingYear],"*")
AND IIf([Forms]![Find]![Price] is not Null,DB.Price=[Forms]![Find]![Price],"*")
AND IIf([Forms]![Find]![Volume]is not Null,DB.Volume=[Forms]![Find]![Volume],"*")
AND IIf([Forms]![Find]![sDate] is not Null AND [Forms]![Find]![eDate] is not Null,DB.TransactionDate= ">" & [Forms]![Find]![sdate] & " and <" & [Forms]![Find]![edate],"*")
);

如果我将它设置为等于它按预期工作的日期之一。我想我在加入约会的方式上遗漏了一些东西

谢谢

标签: sqldatems-accesswhere-clause

解决方案


这(仅适用于日期字段)有效:

WHERE (((DB.TransactionDate)>[Forms]![Find]![sdate] And (DB.TransactionDate)<[Forms]![Find]![edate])) OR ((([Forms]![Find]![sDate]+[Forms]![Find]![eDate]) Is Null));

不要使用 *,它是与Like一起使用的。


推荐阅读