2012-11-05 79 views
0

我在Microsoft Access中有一个联系人数据库,其中包含一个表中的所有数据。我正在尝试创建一个按“状态”对用户进行分组的报告,但我无法确定如何执行此操作。Microsoft Access报告中的一个报告中的分组/多个查询

每个联系人都有两个字段,状态1和状态2.状态1可以为空,A或B,状态2可以为真或假。

报告应组他们是这样的:

Status 1 Null 
    Contact name and details (repeated for every contact with this status) 
Status 1 A 
    Contact name and details (repeated for every contact with this status) 
Status 1 B 
    Contact name and details (repeated for every contact with this status) 
Status 2 True 
    Contact name and details (repeated for every contact with this status) 

还有就是要和这些状态有一些重叠的一些记录匹配多于一个状态,但是这很好。在此页面上显示重复项目是完全可以接受的。

如果这是一个网络应用程序,我会简单地编写4个查询并遍历结果记录集,并在每个适当的标题下显示结果。但在Access报告中,我无法弄清楚要做什么。

谢谢!

回答

1

你可能会考虑在UNION查询立足报告:

SELECT 1 As SortOrder, Contact, Details, Status1, Status2 FROM ContactsTable 
WHERE Status1 Is Null 
UNION ALL 
SELECT 2 As SortOrder, Contact, Details, Status1, Status2 FROM ContactsTable 
WHERE Status1 = "A" 
UNION ALL 
SELECT 3 As SortOrder, Contact, Details, Status1, Status2 FROM ContactsTable 
WHERE Status1 = "B" 
UNION ALL 
SELECT 4 As SortOrder, Contact, Details, Status1, Status2 FROM ContactsTable 
WHERE Status2 = True 
+0

这奏效了,太感谢你了! – Elbelcho