2012-08-13 59 views
0

我碰到了這個How Do I Sequentially Number Records in an Access Query 爲了做我想要做的事情基於這個stackoverflow question我發佈了(我從來沒有做過我以前做的事情)但每次我試圖AS計數器添加到查詢時,我得到在Access 2007中爲查詢添加表達式的正確語法(

The expression you entered contains invalid syntax 
You may have entered an operand without an operator 

使用下面的SQL:

SELECT Maintable.NumBR, Maintable.*, [Ehow] AS Expr1 
FROM Maintable 
WHERE (((Maintable.[NumBR])="" 
    Or (Maintable.[NumBR]) Like "3101" 
    Or (Maintable.[NumBR]) Like "3541" 
    Or (Maintable.[NumBR]) Like "4381" 
    Or (Maintable.[NumBR]) Like "AS3281" 
    Or (Maintable.[NumBR]) Like "4260" 
    Or (Maintable.[NumBR]) Like "4315" 
    Or (Maintable.[NumBR]) Like "4330" 
    Or (Maintable.[NumBR]) Like "4382" 
    Or (Maintable.[NumBR]) Like "9410" 
    Or (Maintable.[NumBR]) Like "9570" 
    Or (Maintable.[NumBR]) Like "AS3710" 
    Or (Maintable.[NumBR]) Like "AS4450" 
    Or (Maintable.[NumBR]) Like "K400" 
    Or (Maintable.[NumBR]) Like "3100" 
    Or (Maintable.[NumBR]) Like "3130" 
    Or (Maintable.[NumBR]) Like "3280" 
    Or (Maintable.[NumBR]) Like "3495" 
    Or (Maintable.[NumBR]) Like "3540" 
    Or (Maintable.[NumBR]) Like "3610" 
    Or (Maintable.[NumBR]) Like "3700" 
    Or (Maintable.[NumBR]) Like "4110" 
    Or (Maintable.[NumBR]) Like "4200") 

AND (([Ehow])=DCount("[NumBR]","[Maintable]"," [NumBR] <= " & [NumBR]))); 

編輯在前面stackove提出的問題rflow問題回答了這個問題。

+0

您對上傳的示例數據庫有什麼不瞭解?你應該發佈樣本數據和你想要返回的例子。 – Fionnuala 2012-08-13 19:53:12

+0

我可以看到你有一個重複的id,當它應該有,但我不知道如何將id添加到找到的記錄。或者如何選擇然後添加一個ID – capnhud 2012-08-13 20:08:18

+0

你看過查詢sql嗎? – Fionnuala 2012-08-13 20:09:37

回答

1

作爲計數器短語在您的查詢不需要。在鏈接的例子中,這被添加到SELECT語句中以別名該列;在你的例子中,你正在使用WHERE從句,所以AS短語不會做任何事情(實際上是無效的)。

+0

這正是我在上一個問題中所說的,長篇討論和示例數據庫。我想知道你的重述是否有幫助。 – Fionnuala 2012-08-13 19:55:11

相關問題