在我的学校项目上工作,当我在ORDER BY
方面添加到我的sql中时,我遇到了这个丢失的操作符错误,尽管其余的代码运行正常。
Set rs_fav = db_kwickfix.OpenRecordset("
SELECT Recipe.Rec_Name
FROM Recipe,Favourites
WHERE (Recipe.RecipeID = Favourites.RecipeID)
AND (Favourites.UserID = " & frm_login.user_id & ")
ORDER BY Recipe.Rec_Name DESCENDING
")
答案 0 :(得分:4)
尝试 DESC
而非 DESCENDING
,请检查ORDER BY Clause (Transact-SQL):
ORDER BY order_by_expression
[COLLATE collation_name]
[ASC | DESC]
[,... n]
[< offset_fetch> ]
因此:
Set rs_fav = db_kwickfix.OpenRecordset("
SELECT Recipe.Rec_Name
FROM Recipe,Favourites
WHERE (Recipe.RecipeID = Favourites.RecipeID)
AND (Favourites.UserID = " & frm_login.user_id & ")
ORDER BY Recipe.Rec_Name DESC
")
答案 1 :(得分:1)
您是否考虑过使用明确的JOIN?
Set rs_fav = db_kwickfix.OpenRecordset("
SELECT Recipe.Rec_Name
FROM Recipe
JOIN Favourites
ON Recipe.RecipeID = Favourites.RecipeID
AND Favourites.UserID = " & frm_login.user_id & "
ORDER BY Recipe.Rec_Name DESC
")
另外,我强烈建议您查看参数化查询,以便开始养成使用它们的习惯。阅读更多相关信息here。