这里是我的关系写一个先进的过滤系统
用户希望能够相应地增加使用下拉菜单中的过滤器和过滤志愿者。过滤器来自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。我很确定有一个简单的方法来做到这一点。有人可以帮帮我吗?谢谢!
你必须之间'V','VWAA联接几个实例'和'VWA',我建议你将它“封装”到视图中以简化一些事情。 – 2015-02-06 09:01:01