Vb6缺少操作员

时间:2016-12-22 15:47:55

标签: sql sql-server vb6

在我的学校项目上工作,当我在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
    ")

2 个答案:

答案 0 :(得分:4)

尝试 DESC 而非 DESCENDING ,请检查ORDER BY Clause (Transact-SQL)

  

ORDER BY order_by_expression
  [COLLATE collat​​ion_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