我有一个参数查询,根据用户输入的开始日期和今天的日期从我的表中选择信息。我想用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();
然后它会提示用户两次输入相同的内容。如何防止这种情况?
答案 0 :(得分:3)
在查询中添加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());