2013-12-13 55 views
0

我需要從簡單查詢中選擇特定數量的隨機行。該號碼以([Formulários]![Survey]![SelectSurveySample])的形式指定。 如果我嘗試選擇TOP 5,它可以工作,但我想在表單中更改此數字。選擇N並在Access中顯示N個隨機行

SELECT TOP ([Formulários]![Survey]![SelectSurveySample]) * 
FROM [main_table] mt 
WHERE (((mt.CPA_Number)=[Formulários]![Survey]![selectCPA_Survey]) 
AND ((mt.Sample_Household)=False) AND ((mt.Functionality_Survey)=False)) 
ORDER BY rnd(Int(Now*ID)-Now*Id) 

回答

0

有你試圖消除括號 ...

SELECT TOP [Formulários]![Survey]![SelectSurveySample] * 
FROM main_table 
WHERE (((main_table.CPA_Number)=[Formulários]![Survey]![selectCPA_Survey]) 
AND ((main_table.Sample_Household)=False) 
AND ((main_table.Functionality_Survey)=False)) 
order by rnd(Int(Now*ID)-Now*Id) 

,因爲這可與更改爲SELECT TOP 5,和你有一個表單變量[Formulários]![Survey]![selectCPA_Survey]在查詢中,我看到的唯一的區別括號

+0

是的我沒有括號嘗試,並返回相同的錯誤。像這樣的東西「SELECT語句包括一個保留字或參數缺少或沒有正確插入或標點符號不正確」(我的訪問不是英文,所以我翻譯了它)。 – user3088281