表:
CS(sid,cid) both int
Courses(id,price) both int
SELECT CS.sid,SUM(Courses.price) as sum FROM CS INNER JOIN Courses ON CS.cid=Courses.id AND CS.sid=@sid GROUP BY CS.sid我想要sum of courses of sid=@sid的价格。@sid是SQLDataSource的参数。
我得到了这个异常:一个类型为'System.Data.OleDb.OleDbException' occurred in System.Web.dll,但未在用户代码中处理的异常
Additional information: The SELECT statement includes a reserved word or an argument name that is misspelled or missing, or the punctuation is incorrect.发布于 2014-12-31 17:58:28
您可能需要使用WHERE
SELECT CS.sid,SUM(Courses.price) as sum FROM CS INNER JOIN Courses ON CS.cid=Courses.id WHERE CS.sid=@sid GROUP BY CS.sid或者,这也可能起作用:
SELECT CS.sid,SUM(Courses.price) as sum FROM CS INNER JOIN Courses ON CS.cid=Courses.id AND ON CS.sid=@sid GROUP BY CS.sid发布于 2014-12-31 21:03:38
SUM是保留字,而您正在尝试选择
SUM(Courses.Price) as Sum... AS SUM令人窒息。尝试更改为
SUM(Courses.Price) as SumOfCourses而且,将命名参数与您要比较的列同名也可能是一个问题。我总是试图强制区分,以防止任何可能的模棱两可的解释,例如更改您的
CS.sid= @sid 当我执行OleDB时,@P是“的参数”,所以我会
CS.sid= @Psid https://stackoverflow.com/questions/27719193
复制相似问题