这是我的关系
用户希望能够使用下拉菜单添加过滤器并相应地过滤志愿者。过滤器来自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 :(得分:0)
如果您希望用户在志愿者工作区的基础上决定志愿者,那么更简单的解决方案将使用子表单。