我有一個組合框有3個值:「是,否,*」。 *旨在代表是和否選項。Microsoft訪問查詢與IIf
在名爲service的字段的條件框內的查詢中。 CompletedOn我已經放置了下面的IIf語句:
IIf([Forms]![serviceReportForm]![workcompletedDropdown] =「Yes」,([service]。[CompletedOn])不爲空([service]。[ CompletedOn])是空)
我想確保在組合框中選擇是時,顯示任何包含完成的值的記錄。如果選擇no,則不顯示,如果選擇*,則顯示所有記錄。目前代碼根本沒有顯示任何記錄。您能否提一些建議?
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不能像那樣使用 – Brad
完整的查詢?你的意思是所有其他領域和標準? – Simon
當然,這個查詢比您所展示的還要多。有一個表和列的某個地方和一個完整的where子句。把這個問題放在這個問題上會非常有幫助。 – Brad