表:
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.
答案 0 :(得分:0)
您可能需要使用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
答案 1 :(得分:0)
SUM是保留字,您正在尝试选择
SUM(Courses.Price) as Sum...
AS SUM令人窒息。尝试更改为
SUM(Courses.Price) as SumOfCourses
此外,将命名参数与您要比较的列同名可能是一个问题。我总是尝试强制区分以防止任何可能的模糊解释,例如更改
CS.sid= @sid
当我做OleDB时,@ P是“参数”,所以我会有
CS.sid= @Psid