SQL操作时出现INNER附近有语法错误,望告之如何解决
发布网友
发布时间:2022-05-09 20:37
我来回答
共3个回答
热心网友
时间:2023-10-18 11:09
" AND s.IOId= " + cIOId + " INNER JOIN Proct p ON l.ProId = p.ProId "
加2个单引号改成
" AND s.IOId= '" + cIOId + "' INNER JOIN Proct p ON l.ProId = p.ProId "
另外对于null值得判断可以用到函数
" (CASE WHEN s.IONum IS NULL THEN 0 ELSE s.IONum END) AS 实际入库数量,"
" (CASE WHEN s.IONum IS NULL THEN 0 ELSE s.IONum*l.Price END) AS 实际入库金额, "
如果是sqlserver,改成
" isnull(s.IONum,0) AS 实际入库数量,"
" isnull(s.IONum,0)*l.Price AS 实际入库金额, "
如果是ORACLE,改成
" NVL(s.IONum,0) AS 实际入库数量,"
" NVL(s.IONum,0)*l.Price AS 实际入库金额, "
热心网友
时间:2023-10-18 11:09
" AND s.IOId= " + cIOId + " INNER JOIN Proct p ON l.ProId = p.ProId "
这句,cIOId地方少了个点
应该是c.IOId
热心网友
时间:2023-10-18 11:10
CString cSql;
if(nFlag==0 || nFlag==3) // 从表PurProctList中提取此PurId下的记录
cSql = " SELECT l.ProId AS 商品编号,p.ProName AS 商品名称, "
" p.ProStyle AS 商品型号,p.ProUnit AS 单位,c.CustName AS 客户名称, "
" l.Quantity AS 应入库数量,l.Price AS 入库价格, "
" (CASE WHEN s.IONum IS NULL THEN 0 ELSE s.IONum END) AS 实际入库数量,"
" (CASE WHEN s.IONum IS NULL THEN 0 ELSE s.IONum*l.Price END) AS 实际入库金额, "
" p.TypeId,s.ListId FROM PurProctList l LEFT JOIN StoreIOList s ON l.ProId = s.ProId "
" AND s.IOId= " + cIOId + " INNER left Proct p ON l.ProId = p.ProId "
" INNER JOIN Customer c ON l.CustId = c.CustId "
" WHERE l.Purid=' " + m_dcoList.GetBoundText() + "'"
" ORDER BY l.ProId ";
right join 或者 left join