有人可以帮我解决这个问题吗,我运行代码时出现语法错误,我不知道它可能是什么...提前感谢
SqlCommand scGetPostings = new SqlCommand ("SELECT D1.dr,D1.cr,d1.asset_no ,(open_bal+dr-cr) as closing_balance FROM" +
"(SELECT COALESCE(SUM(dr_amount),0) as dr, COALESCE(SUM(cr_amount),0) as cr,invasset.asset_no FROM posting,sysasset,invasset" +
"WHERE posting.asset_no = invasset.asset_no AND posting.asset_no = @AssetNo, AND period >= asset_open_per GROUP BY invasset.asset_no)" +
"as D1,asset", DataAccess.AConnection);
答案 0 :(得分:2)
在行的末尾添加一些空格,否则这是连接的结果:
FROM(SELECT
invassetWHERE posting.asset_no
...
更新:
实际错误来自WHERE posting.asset_no
< - 此点。因为未解析where子句,并且posting.asset_no
需要作为表名
答案 1 :(得分:1)
问题在于where子句:
WHERE posting.asset_no = invasset.asset_no AND posting.asset_no = @AssetNo, AND period >= asset_open_per
删除逗号,它应该有效。像这样:
WHERE posting.asset_no = invasset.asset_no AND posting.asset_no = @AssetNo AND period >= asset_open_per
答案 2 :(得分:1)
SqlCommand scGetPostings = new SqlCommand ("SELECT D1.dr,D1.cr,d1.asset_no ,(open_bal+dr-cr) as closing_balance FROM " +
"(SELECT COALESCE(SUM(dr_amount),0) as dr, COALESCE(SUM(cr_amount),0) as cr,invasset.asset_no FROM posting,sysasset,invasset" +
" WHERE posting.asset_no = invasset.asset_no AND posting.asset_no = @AssetNo AND period >= asset_open_per GROUP BY invasset.asset_no )" +
"AS D1,asset", DataAccess.AConnection);
答案 3 :(得分:1)
在字符串片段的末尾添加空格!
"(SELECT ...,sysasset,invasset " +
"WHERE ... invasset.asset_no)"
而不是
"(SELECT ...,sysasset,invasset" +
"WHERE ... invasset.asset_no)"
答案 4 :(得分:1)
摆脱,
AND posting.asset_no = @AssetNo