2015-02-05 93 views
2

這裏是我的關係寫一個先進的過濾系統

enter image description here

用戶希望能夠相應地增加使用下拉菜單中的過濾器和過濾志願者。過濾器來自VolunteerWorkArea表(VolunteerWorkAreaId)。我要做到這一點很痛苦,可能是因爲缺乏知識。每次用戶添加一個新的過濾器時,我都必須以一種複雜的方式更改SQL。例如,這是用戶添加三個過濾器後的SQL。

SELECT DISTINCT 
     Volunteer.VolunteerId AS Volunteer_VolunteerId , 
     Volunteer.VolunteerFirstName , 
     Volunteer.VolunteerLastName , 
     Volunteer.VolunteerOtherName , 
     Volunteer.VolunteerStreetAddress , 
     Volunteer.VolunteerSuburb , 
     Volunteer.VolunteerPostCode , 
     Volunteer.VolunteerHomePhone , 
     Volunteer.VolunteerMobilePhone , 
     Volunteer.VolunteerGender 
FROM Volunteer 
     INNER JOIN (VolunteerWorkArea 
        INNER JOIN VolunteerWorkAreaAllocation ON VolunteerWorkArea.VolunteerWorkAreaId = VolunteerWorkAreaAllocation.VolunteerWorkAreaId 
        ) ON Volunteer.VolunteerId = VolunteerWorkAreaAllocation.VolunteerId 
WHERE VolunteerWorkAreaAllocation.[VolunteerWorkAreaId] = 17 
     AND Volunteer.VolunteerId IN (
     SELECT DISTINCT 
       Volunteer.VolunteerId 
     FROM Volunteer 
       INNER JOIN (VolunteerWorkArea 
          INNER JOIN VolunteerWorkAreaAllocation ON VolunteerWorkArea.[VolunteerWorkAreaId] = VolunteerWorkAreaAllocation.[VolunteerWorkAreaId] 
          ) ON Volunteer.[VolunteerId] = VolunteerWorkAreaAllocation.[VolunteerId] 
     WHERE VolunteerWorkAreaAllocation.[VolunteerWorkAreaId] = 16 
       AND Volunteer.VolunteerId IN (
       SELECT DISTINCT 
         Volunteer.VolunteerId AS Volunteer_VolunteerId 
       FROM Volunteer 
         INNER JOIN (VolunteerWorkArea 
            INNER 
JOIN VolunteerWorkAreaAllocation ON VolunteerWorkArea.[VolunteerWorkAreaId] = VolunteerWorkAreaAllocation.[VolunteerWorkAreaId] 
            ) ON Volunteer.[VolunteerId] = VolunteerWorkAreaAllocation.[VolunteerId] 
       WHERE VolunteerWorkAreaAllocation.[VolunteerWorkAreaId] = 15)); 

因此,每次用戶添加過濾器時,我都必須通過代碼大量更改SQL。我很確定有一個簡單的方法來做到這一點。有人可以幫幫我嗎?謝謝!

+0

你必須之間'V','VWAA聯接幾個實例'和'VWA',我建議你將它「封裝」到視圖中以簡化一些事情。 – 2015-02-06 09:01:01

回答

0

如果希望用戶volunteerWorkArea的基礎上,決定志願者那麼容易的解決方案將使用窗體。

  1. 創建不基於任何表
  2. 創建和使用嚮導 綁定組合框與volunteerWorkArea表的新形式(比如名稱:combo2)。
  3. 創建一個子窗體,並與其他兩個表,即志願者 & volunteerWorkAreaAllocation圖像具有更少的字段數爲 樣品)通過可見屬性設置爲false
  4. 隱藏ID字段綁定。
  5. 集子控件屬性,如圖圖像(combo2作爲主 字段和兒童爲volunteerWorkAreaID

enter image description here

+1

真的很抱歉,因爲後期的反應非常不同。我離開IT一段時間:( – 2017-08-08 04:36:17