sql - 多次提示用户输入相同的查询参数 (MS-Access)

标签 sql ms-access query-parameters

我有一个参数查询,它根据用户输入的开始日期和今天的日期从我的表中选择信息。我想使用 WHERE 语句在我的表中搜索两个字段,而无需两次输入开始日期的提示。现在我有:

SELECT PatientSurvey.PatientID
FROM PatientSurvey
WHERE (PatientSurvey.[6MonthSurveyReturn] OR PatientSurvey.[12MonthSurveyReturn]) Between [Enter the last date checked for:] And Date();

这似乎不起作用。但是,如果我执行以下操作:
SELECT PatientSurvey.PatientID
FROM PatientSurvey
WHERE (PatientSurvey.[6MonthSurveyReturn]) Between [Enter the last date checked for:] And Date() OR (PatientSurvey.[12MonthSurveyReturn]) Between [Enter the last date checked for:] And Date();

然后它会针对相同的输入提示用户两次。 如何防止这种情况发生?

最佳答案

将 PARAMETERS 声明添加到您的查询中。

PARAMETERS [Enter the last date checked for:] DateTime;
SELECT PatientSurvey.PatientID
FROM PatientSurvey
WHERE
       (([PatientSurvey].[6MonthSurveyReturn]) Between [Enter the last date checked for:] And Date())
    OR (([PatientSurvey].[12MonthSurveyReturn]) Between [Enter the last date checked for:] And Date());

关于sql - 多次提示用户输入相同的查询参数 (MS-Access),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6949882/

相关文章:

php - 处理在 MySQL 中存储为 JSON 对象的数据

mysql - 如何删除表的所有外键

javascript - URLSearchParams 可以让参数不区分大小写吗?

sql - 如何将列添加到 generate_series 查询

sql-server - 自动将新数据从 MS Access 数据库导入 SQL Server

c# - 如何使用 .NET 中的 OleDb 命名空间连接到 Access 数据库?

sql - 使用 ComboBox 值作为 SQL 查询的一部分? (MS Access 2010-2013)

ruby-on-rails - 将查询字符串中的多维数组传递给 Rails 中的 Controller

javascript - 如何在 Express 中获取 URL 参数?

MySQL 查询一对多关系且仅返回一行