2012-11-05 77 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