Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/70.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Sql 编写高级过滤系统_Sql_Ms Access_Vba - Fatal编程技术网

Sql 编写高级过滤系统

Sql 编写高级过滤系统,sql,ms-access,vba,Sql,Ms Access,Vba,这是我的关系 用户希望能够使用下拉菜单添加过滤器,并相应地过滤志愿者。筛选器来自志愿者工作区表(志愿者工作区ID)。我这样做很痛苦,可能是因为缺乏知识。每次用户添加新过滤器时,我都必须以复杂的方式更改SQL。例如,这是用户添加三个过滤器后的SQL SELECT DISTINCT Volunteer.VolunteerId AS Volunteer_VolunteerId , Volunteer.VolunteerFirstName , Volun

这是我的关系

用户希望能够使用下拉菜单添加过滤器,并相应地过滤志愿者。筛选器来自
志愿者工作区
表(
志愿者工作区ID
)。我这样做很痛苦,可能是因为缺乏知识。每次用户添加新过滤器时,我都必须以复杂的方式更改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。我确信有一个简单的方法可以做到这一点。有人能帮我吗?谢谢

如果您希望用户根据志愿者工作区决定志愿者,那么更简单的解决方案是使用子表单

  • 创建不基于任何表的新表单
  • 使用向导创建并绑定带有工作区的组合框 (说出姓名:combo2)
  • 创建一个子表单并将其与其他两个表绑定,即志愿者& 自愿工作区分配(图像中的 (样本)
  • 通过将visible属性设置为false来隐藏ID字段
  • 将子窗体控件属性设置为主窗体,如图(combo2所示 字段和子字段为工作区ID

  • 您有几个连接
    V
    VWAA
    VWA
    的实例,我建议您将它们“封装”到一个视图中,以简化一些事情。非常抱歉,反应太晚了。我离开它有一段时间了:(