【发布时间】:2016-06-07 16:11:27
【问题描述】:
我有一个包含 3 个值的组合框:“是、否、*”。 * 用于表示是和否选项。
在名为服务的字段的条件框中的查询中。 CompletedOn 我已经放置了下面的 IIf 语句:
IIf([Forms]![serviceReportForm]![workcompletedDropdown]="Yes",([service].[CompletedOn]) 不为空,([service].[CompletedOn]) 为空)
我试图确保在组合框中选择“是”时,会显示包含已完成值的任何记录。如果选择否,则不显示,如果选择 *,则显示所有记录。目前,代码根本没有显示任何记录。可以请教吗?
下面的SQL
SELECT customer.CustomerID,
customer.[Customer Name],
Equipment.Description,
Equipment.PurchaseID,
service.Date,
service.Fault,
service.JobNo,
service.costOfRepair,
service.ServiceID,
service.CompletedOn,
CalloutUrgency.CalloutDescription,
CalloutUrgency.CalloutUrgencyID,
service.AgentID,
agent.Serviceagentname,
supplier.supplierID,
supplier.supplierName,
Equipment.ManufacturerID,
Manufacturer.[Manufacturer Name]
FROM Manufacturer
INNER JOIN ((customer
INNER JOIN (supplier
INNER JOIN Equipment
ON supplier.supplierID = Equipment.SupplierID)
ON customer.CustomerID = Equipment.CustomerID)
INNER JOIN (agent
INNER JOIN (CalloutUrgency
INNER JOIN service
ON CalloutUrgency.CalloutUrgencyID = service.CalloutUrgencyID)
ON agent.AgentID = service.AgentID)
ON Equipment.EquipmentID = service.EquipmentID)
ON Manufacturer.ManufacturerID = Equipment.ManufacturerID
WHERE (((customer.[Customer Name]) Like [Forms]![ServiceReportForm]![houseDropdown])
AND ((service.Date) Between [Forms]![ServiceReportForm].[fromDate] And [Forms]![ServiceReportForm].[toDate])
AND ((service.CompletedOn)=IIf([Forms]![ServiceReportForm]![workcompletedDropdown]="Yes",Not Null,Null))
AND ((CalloutUrgency.CalloutDescription) Like [Forms]![ServiceReportForm]![urgencyDropdown])
AND ((agent.Serviceagentname) Like [Forms]![ServiceReportForm]![serviceagentDropdown])
AND ((supplier.supplierName) Like [Forms]![ServiceReportForm]![supplierDropdown]))
OR (((service.Date) Between [Forms]![ServiceReportForm].[fromDate] And [Forms]![ServiceReportForm].[toDate])
AND (([Forms]![ServiceReportForm])=" All"));
【问题讨论】:
-
你能显示你的完整查询吗?看起来您正在尝试制作动态 sql,但 iif 不能那样使用
-
完整查询?您是指所有其他字段和标准吗?
-
这个查询肯定比你显示的更多。某处有一个表和列,还有一个完整的 where 子句。把它放在问题中会很有帮助。
-
有没有办法以可读的格式打印出来?即,一个单一的声明?目前我正在查看查询编辑器,其中有很多包含不同字段和代码位的框,因此很难显示整个查询
-
您可以在功能区左上角将视图从设计视图更改为 SQL 视图。或者点击整个窗口左下角的SQL。
标签: ms-access