视图的编写
麻烦帮忙看一下以下语句,哪里出错,我应该如何修改?
SELECT distinct dbo.Customer.cCusAbbName AS 客户简称, dbo.SO_SOMain.cSOCode AS 订单号,dbo.SO_SOMain.dDate AS 订单日期, dbo.Person.cPersonName AS 业务员, dbo.Inventory.cInvCode AS 存货编码,dbo.Inventory.cInvName AS 存货名称, dbo.Inventory.cInvStd AS 规格型号,dbo.SO_SODetails.iQuantity AS 数量,dbo.ComputationUnit.cComUnitName AS 主计量, dbo.SO_SODetails.iTaxUnitPrice AS 含税单价,dbo.SO_SODetails.iSum AS 价税合计, ISNULL(dbo.SO_SODetails.foutquantity, 0) AS 出库数量, (case when isnull(sum(distinct RdRecords.iQuantity),0)=0 then isnull(sum(distinct RdRecords.iQuantity),0)+ISNULL(dbo.SO_SODetails.foutquantity, 0) else isnull(sum(distinct RdRecords.iQuantity),0) end) as 累计入库数量, MAX(dbo.RdRecord.dDate) AS 入库最后日期,dbo.SO_SODetails.dPreDate AS 预发货日期, MAX(dbo.DispatchList.dDate) AS 最后发货日期, dbo.SO_SODetails.iFHQuantity AS 累计发货数量,dbo.SO_SOMain.cCusOAddress AS 发货地址, dbo.SO_SODetails.fretquantity AS 累计退货数量, dbo.SO_SODetails.iKPQuantity AS 累计开票数量,dbo.SO_SODetails.iKPMoney AS 累计开票金额, ISNULL(dbo.SO_SODetails.imoneysum, 0) AS 累计收款,ISNULL(dbo.SO_SODetails.iexchsum, 0) AS 累计收款原币, dbo.SO_SOMain.cMaker AS 制单人,dbo.SO_SOMain.cVerifier AS 审核人,dbo.SO_SOMain.cCloser AS 关闭人, dbo.SO_SODetails.cSCloser AS 行关闭人FROM dbo.SO_SODetails right outer join dbo.Inventory on dbo.Inventory.cInvCode = dbo.SO_SODetails.cInvCode left outer join dbo.ComputationUnit on dbo.Inventory.cComUnitCode = dbo.ComputationUnit.cComunitCode on dbo.SO_SODetails.cUnitID = ComputationUnit.cComunitCode right outer join dbo.so_somain on dbo.so_somain.csocode=dbo.so_sodetails.csocode left outer join dbo.Person ON dbo.Person.cPersonCode=dbo.SO_SOMain.cPersonCode on dbo.SO_SODetails.ID = dbo.SO_SOMain.ID right outer join dbo.Customer on dbo.Customer.cCusCode = dbo.SO_SOMain.cCusCode left outer join dbo.RdRecord ON dbo.SO_SODetails.cSOCode = dbo.RdRecord.cDefine10 RIGHT OUTER JOIN dbo.RdRecords ON dbo.RdRecord.ID = dbo.RdRecords.ID AND dbo.SO_SODetails.cInvCode = dbo.RdRecords.cInvCode on dbo.SO_SOMain.cSOCode = dbo.RdRecord.cDefine10 LEFT OUTER JOIN dbo.DispatchList ON dbo.DispatchList.cSOCode = dbo.RdRecord.cDefine10 group by dbo.Customer.cCusAbbName,dbo.SO_SOMain.cSOCode,dbo.SO_SOMain.dDate,dbo.Person.cPersonName,dbo.Inventory.cInvCode, dbo.Inventory.cInvName,dbo.Inventory.cInvStd,dbo.SO_SODetails.iQuantity,dbo.ComputationUnit.cComUnitName,dbo.SO_SODetails.iTaxUnitPrice, dbo.SO_SODetails.iSum,dbo.SO_SODetails.foutquantity,dbo.SO_SODetails.dPreDate,dbo.SO_SODetails.iFHQuantity,dbo.SO_SOMain.cCusOAddress, dbo.SO_SODetails.fretquantity,dbo.SO_SODetails.iKPQuantity,dbo.SO_SODetails.iKPMoney,dbo.SO_SODetails.imoneysum,dbo.SO_SODetails.iexchsum, dbo.SO_SOMain.cMaker,dbo.SO_SOMain.cVerifier,dbo.SO_SOMain.cCloser,dbo.SO_SODetails.cSCloser
FROM dbo.SO_SODetails right outer join dbo.Inventory on dbo.Inventory.cInvCode = dbo.SO_SODetails.cInvCode left outer join dbo.ComputationUnit on dbo.Inventory.cComUnitCode = dbo.ComputationUnit.cComunitCode [color=#00FFFF]and [/color]dbo.SO_SODetails.cUnitID = ComputationUnit.cComunitCode right outer join dbo.so_somain on dbo.so_somain.csocode=dbo.so_sodetails.csocode left outer join dbo.Person ON dbo.Person.cPersonCode=dbo.SO_SOMain.cPersonCode [color=#00FF00]and [/color]dbo.SO_SODetails.ID = dbo.SO_SOMain.ID right outer join dbo.Customer on dbo.Customer.cCusCode = dbo.SO_SOMain.cCusCode left outer join dbo.RdRecord ON dbo.SO_SODetails.cSOCode = dbo.RdRecord.cDefine10 RIGHT OUTER JOIN dbo.RdRecords ON dbo.RdRecord.ID = dbo.RdRecords.ID AND dbo.SO_SODetails.cInvCode = dbo.RdRecords.cInvCode [color=#00FFFF]and [/color]dbo.SO_SOMain.cSOCode = dbo.RdRecord.cDefine10 LEFT OUTER JOIN dbo.DispatchList ON dbo.DispatchList.cSOCode = dbo.RdRecord.cDefine10试试这样还报错不?
[解决办法]
连接两个表的多条件用AND /OR 等其他连接语法,不是ON,
[解决办法]
有三个on需要改成and
SELECT DISTINCT dbo.Customer.cCusAbbName AS 客户简称 , dbo.SO_SOMain.cSOCode AS 订单号 , dbo.SO_SOMain.dDate AS 订单日期 , dbo.Person.cPersonName AS 业务员 , dbo.Inventory.cInvCode AS 存货编码 , dbo.Inventory.cInvName AS 存货名称 , dbo.Inventory.cInvStd AS 规格型号 , dbo.SO_SODetails.iQuantity AS 数量 , dbo.ComputationUnit.cComUnitName AS 主计量 , dbo.SO_SODetails.iTaxUnitPrice AS 含税单价 , dbo.SO_SODetails.iSum AS 价税合计 , ISNULL(dbo.SO_SODetails.foutquantity, 0) AS 出库数量 , ( CASE WHEN ISNULL(SUM(DISTINCT RdRecords.iQuantity), 0) = 0 THEN ISNULL(SUM(DISTINCT RdRecords.iQuantity), 0) + ISNULL(dbo.SO_SODetails.foutquantity, 0) ELSE ISNULL(SUM(DISTINCT RdRecords.iQuantity), 0) END ) AS 累计入库数量 , MAX(dbo.RdRecord.dDate) AS 入库最后日期 , dbo.SO_SODetails.dPreDate AS 预发货日期 , MAX(dbo.DispatchList.dDate) AS 最后发货日期 , dbo.SO_SODetails.iFHQuantity AS 累计发货数量 , dbo.SO_SOMain.cCusOAddress AS 发货地址 , dbo.SO_SODetails.fretquantity AS 累计退货数量 , dbo.SO_SODetails.iKPQuantity AS 累计开票数量 , dbo.SO_SODetails.iKPMoney AS 累计开票金额 , ISNULL(dbo.SO_SODetails.imoneysum, 0) AS 累计收款 , ISNULL(dbo.SO_SODetails.iexchsum, 0) AS 累计收款原币 , dbo.SO_SOMain.cMaker AS 制单人 , dbo.SO_SOMain.cVerifier AS 审核人 , dbo.SO_SOMain.cCloser AS 关闭人 , dbo.SO_SODetails.cSCloser AS 行关闭人FROM dbo.SO_SODetails RIGHT OUTER JOIN dbo.Inventory ON dbo.Inventory.cInvCode = dbo.SO_SODetails.cInvCode LEFT OUTER JOIN dbo.ComputationUnit ON dbo.Inventory.cComUnitCode = dbo.ComputationUnit.cComunitCode AND dbo.SO_SODetails.cUnitID = ComputationUnit.cComunitCode RIGHT OUTER JOIN dbo.so_somain ON dbo.so_somain.csocode = dbo.so_sodetails.csocode LEFT OUTER JOIN dbo.Person ON dbo.Person.cPersonCode = dbo.SO_SOMain.cPersonCode AND dbo.SO_SODetails.ID = dbo.SO_SOMain.ID RIGHT OUTER JOIN dbo.Customer ON dbo.Customer.cCusCode = dbo.SO_SOMain.cCusCode LEFT OUTER JOIN dbo.RdRecord ON dbo.SO_SODetails.cSOCode = dbo.RdRecord.cDefine10 RIGHT OUTER JOIN dbo.RdRecords ON dbo.RdRecord.ID = dbo.RdRecords.ID AND dbo.SO_SODetails.cInvCode = dbo.RdRecords.cInvCode AND dbo.SO_SOMain.cSOCode = dbo.RdRecord.cDefine10 LEFT OUTER JOIN dbo.DispatchList ON dbo.DispatchList.cSOCode = dbo.RdRecord.cDefine10GROUP BY dbo.Customer.cCusAbbName , dbo.SO_SOMain.cSOCode , dbo.SO_SOMain.dDate , dbo.Person.cPersonName , dbo.Inventory.cInvCode , dbo.Inventory.cInvName , dbo.Inventory.cInvStd , dbo.SO_SODetails.iQuantity , dbo.ComputationUnit.cComUnitName , dbo.SO_SODetails.iTaxUnitPrice , dbo.SO_SODetails.iSum , dbo.SO_SODetails.foutquantity , dbo.SO_SODetails.dPreDate , dbo.SO_SODetails.iFHQuantity , dbo.SO_SOMain.cCusOAddress , dbo.SO_SODetails.fretquantity , dbo.SO_SODetails.iKPQuantity , dbo.SO_SODetails.iKPMoney , dbo.SO_SODetails.imoneysum , dbo.SO_SODetails.iexchsum , dbo.SO_SOMain.cMaker , dbo.SO_SOMain.cVerifier , dbo.SO_SOMain.cCloser , dbo.SO_SODetails.cSCloser
[解决办法]