访问SQL:根据条件选择table到SELECT
Access SQL: Choosing which table to SELECT from based on a condition
考虑以下情况:
我有一大组查询 select 来自其他查询 select 来自其他查询,这些查询的任务是将出勤表中的出席、迟到和缺席相加,计算百分比等。现在客户希望能够在查询中加入许多不同的条件:仅查看一周中特定日期的出勤率、仅查看特定日期范围内的出勤率等。
执行每个条件所需的所有计算将非常耗时,因此我希望仅在客户端请求执行该计算时才执行计算。但我不想为每种可以使用的条件类型重新创建我的整个 queries/reports 集。所以我想做这样的事情:
SELECT * FROM
IIf([a checkbox on a form that indicates whether the user wants the condition],
SELECT * FROM Attendance,
SELECT * FROM Attendance WHERE condition)
因为我不想在用户不想要的情况下完成计算,所以这不是解决方案:
SELECT * FROM Attendance
WHERE condition
OR NOT [a checkbox on a form that indicates whether the user wants the condition]
在 Access SQL 中有什么方法可以做到这一点吗?
逻辑的正确表达方式是:
SELECT *
FROM Attendance
WHERE ([a checkbox on a form that indicates whether the user wants the condition] and condition) or
(not [a checkbox on a form that indicates whether the user wants the condition] )
此公式可能允许 MS Access 不评估条件。
如果您需要两个不同的查询 运行,具体取决于用户的选择,请在应用程序中构建两个不同的查询并选择合适的查询。
考虑以下情况:
我有一大组查询 select 来自其他查询 select 来自其他查询,这些查询的任务是将出勤表中的出席、迟到和缺席相加,计算百分比等。现在客户希望能够在查询中加入许多不同的条件:仅查看一周中特定日期的出勤率、仅查看特定日期范围内的出勤率等。
执行每个条件所需的所有计算将非常耗时,因此我希望仅在客户端请求执行该计算时才执行计算。但我不想为每种可以使用的条件类型重新创建我的整个 queries/reports 集。所以我想做这样的事情:
SELECT * FROM
IIf([a checkbox on a form that indicates whether the user wants the condition],
SELECT * FROM Attendance,
SELECT * FROM Attendance WHERE condition)
因为我不想在用户不想要的情况下完成计算,所以这不是解决方案:
SELECT * FROM Attendance
WHERE condition
OR NOT [a checkbox on a form that indicates whether the user wants the condition]
在 Access SQL 中有什么方法可以做到这一点吗?
逻辑的正确表达方式是:
SELECT *
FROM Attendance
WHERE ([a checkbox on a form that indicates whether the user wants the condition] and condition) or
(not [a checkbox on a form that indicates whether the user wants the condition] )
此公式可能允许 MS Access 不评估条件。
如果您需要两个不同的查询 运行,具体取决于用户的选择,请在应用程序中构建两个不同的查询并选择合适的查询。