2015-02-05 57 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