2011-08-04 62 views
2

我有一個參數查詢,根據用戶輸入的開始日期和當前日期從我的表中選擇信息。我想用WHERE語句在表格中搜索兩個字段,而不是兩次輸入開始日期的提示。現在我有:不止一次提示用戶輸入相同的查詢參數(MS-Access)

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(); 

然後,它會提示用戶兩次相同的輸入。這怎麼能防止?

回答

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()); 
+0

非常感謝您的幫助! – jrubins

相關問題