【发布时间】:2013-10-24 13:31:26
【问题描述】:
我有一个查询和一个表。表的名称是 OrderT,而查询的名称是 SearchQ。查询在那里,所以我可以让一个子表单在表单上显示搜索结果。尽管如果我的查询缺少任何字段中的任何数据,我的查询将不会在表格上显示一行。例如,如果我有字段 CustomerName、OrderNumber 和 OrderDueDate,我填写了 CustomerName、OrderNumber 但将 OrderDueDate 留空;查询不会显示它存在,因此搜索无法找到它。
我将如何让查询显示表中的所有内容,即使某些字段没有填写?
查询的SQL:
SELECT OrderT.CustomerName, OrderT.OrderName, OrderT.OrderDesc, OrderT.DateOfPurchase, OrderT.ProjectDueDate, OrderT.EngineerDueDate, OrderT.ProjectComplete, OrderT.CutplanDueDate, OrderT.MaterialSpecs, OrderT.CutplanCode, OrderT.HardwareSpecs, OrderT.HardwareDueDate, OrderT.HardwareComplete, OrderT.PurchaseOrder, OrderT.PurchaseSupplier
FROM OrderT
WHERE (((OrderT.CustomerName) Like "*" & [Forms]![SearchF]![CustomerName] & "*") AND ((OrderT.OrderName) Like "*" & [Forms]![SearchF]![OrderName] & "*") AND ((OrderT.OrderDesc) Like "*" & [Forms]![SearchF]![OrderDesc] & "*") AND ((OrderT.DateOfPurchase) Like "*" & [Forms]![SearchF]![DateOfPurchase] & "*") AND ((OrderT.ProjectDueDate) Like "*" & [Forms]![SearchF]![ProjectDueDate] & "*") AND ((OrderT.EngineerDueDate) Like "*" & [Forms]![SearchF]![EngineerDueDate] & "*") AND ((OrderT.ProjectComplete) Like "*" & [Forms]![SearchF]![ProjectComplete] & "*") AND ((OrderT.CutplanDueDate) Like "*" & [Forms]![SearchF]![CutplanDueDate] & "*") AND ((OrderT.MaterialSpecs) Like "*" & [Forms]![SearchF]![MaterialSpecs] & "*") AND ((OrderT.CutplanCode) Like "*" & [Forms]![SearchF]![CutplanCode] & "*") AND ((OrderT.HardwareSpecs) Like "*" & [Forms]![SearchF]![HardwareSpecs] & "*") AND ((OrderT.HardwareDueDate) Like "*" & [Forms]![SearchF]![HardwareDueDate] & "*") AND ((OrderT.HardwareComplete) Like "*" & [Forms]![SearchF]![HardwareComplete] & "*") AND ((OrderT.PurchaseOrder) Like "*" & [Forms]![SearchF]![PurchaseOrder] & "*") AND ((OrderT.PurchaseSupplier) Like "*" & [Forms]![SearchF]![PurchaseSupplier] & "*"));
【问题讨论】:
-
请向我们展示查询 SQL。我从来没有听说过这样的事情,除非有一个 join 或 WHERE 子句排除基于给定字段的记录。
-
字段的值未在表格或搜索表单中输入?
-
假设我在我的表 OrderT 中输入了数据,并留下了 OrderName,因为没有此特定产品的订单号。查询将不接受整行,并且就好像它不存在一样,使基于查询的子表单也无法获取数据,因此当您使用表单通过我的搜索按钮搜索数据时;它不会找到它,因为它认为它不存在,但它显然在表中。