Sql server 无法绑定多部分标识符“p.ProductID”
我有一些SQL在mssql平台上可以很好地执行,但我们从开关站执行它,驼峰流SQL绑定它不工作 sql是Sql server 无法绑定多部分标识符“p.ProductID”,sql-server,sql-server-2008,apache-camel,inner-join,switchyard,Sql Server,Sql Server 2008,Apache Camel,Inner Join,Switchyard,我有一些SQL在mssql平台上可以很好地执行,但我们从开关站执行它,驼峰流SQL绑定它不工作 sql是 SELECT p.ProductID,p.dtGTIN,p.ProductWeight ,p.dtPurchasePriceUnit,p.dtItemGroupID, p.dtPromotionID,p.IntroductionDate,p.dtOnOrder, p.dtExposureGroup,p.dtPlanogram,p.ProductHeight, p.ProductW
SELECT
p.ProductID,p.dtGTIN,p.ProductWeight
,p.dtPurchasePriceUnit,p.dtItemGroupID,
p.dtPromotionID,p.IntroductionDate,p.dtOnOrder,
p.dtExposureGroup,p.dtPlanogram,p.ProductHeight,
p.ProductWidth,p.ProductLength,p.dtPackageSize1,
p.productHeightUOMID,p.productWidthUOMID,p.productLengthUOMID,
pn.dtProductNameDescription1,pn.dtProductNameDescription2,
pv.VendorID,pr.ReferenceNumber
FROM ODS_Product p
JOIN ODS_ProductName pn
ON pn.ProductID=p.ProductID and pn.BusinessUnitId=p.BusinessUnitId
JOIN ODS_ProductVendor pv
ON pv.ProductID=p.ProductID and pv.BusinessUnitId=p.BusinessUnitId
LEFT JOIN ODS_dtProductReference pr
ON (pr.ProductID=p.ProductID and pr.BusinessUnitId=p.BusinessUnitId and
pr.ReferenceID='SRII')
where p.ProductID=# and p.BusinessUnitId=#
信息是
Caused by exception of type com.microsoft.sqlserver.jdbc.SQLServerException,
message: com.microsoft.sqlserver.jdbc.SQLServerException: The multi-part
identifier "p.ProductID" could not be bound.:
org.switchyard.HandlerException: org.switchyard.HandlerException:
org.springframework.jdbc.UncategorizedSQLException:
PreparedStatementCallback; uncategorized SQLException for SQL. SQL state
[null]; error code [0]; com.microsoft.sqlserver.jdbc.SQLServerException: The
multi-part identifier "p.ProductID" could not be bound.; nested exception is
com.microsoft.sqlserver.jdbc.SQLServerException:
com.microsoft.sqlserver.jdbc.SQLServerException: The multi-part identifier
"p.ProductID" could not be bound.
知道为什么吗?据我所知,您不能使用and in Join子句。请尝试从join语句中删除and部分
SELECT
p.ProductID,p.dtGTIN,p.ProductWeight
,p.dtPurchasePriceUnit,p.dtItemGroupID,
p.dtPromotionID,p.IntroductionDate,p.dtOnOrder,
p.dtExposureGroup,p.dtPlanogram,p.ProductHeight,
p.ProductWidth,p.ProductLength,p.dtPackageSize1,
p.productHeightUOMID,p.productWidthUOMID,p.productLengthUOMID,
pn.dtProductNameDescription1,pn.dtProductNameDescription2,
pv.VendorID,pr.ReferenceNumber
FROM ODS_Product p
JOIN ODS_ProductName pn
ON pn.ProductID=p.ProductID
join ODS_ProductName pn1 pn1.BusinessUnitId=p.BusinessUnitId
JOIN ODS_ProductVendor pv
ON pv.ProductID=p.ProductID
JOIN ODS_ProductVendor Pv1 pv1.BusinessUnitId=p.BusinessUnitId
LEFT JOIN ODS_dtProductReference pr
where p.ProductID=# and p.BusinessUnitId=#
我不确定,但它可能对你有帮助 找到了解决办法。问题是sql驱动程序准备了语句之类的东西。由于某种原因,它无法解释p.productId,因此当我从SQL中删除所有别名时,它工作了,但我不知道为什么:
SELECT ODS_Product.ProductID,ODS_Product.dtGTIN,ODS_Product.ProductWeight
,ODS_Product.dtPurchasePriceUnit,ODS_Product.dtItemGroupID,
ODS_Product.dtPromotionID,ODS_Product.IntroductionDate,
ODS_Product.dtOnOrder,ODS_Product.dtExposureGroup,ODS_Product.dtPlanogram,
ODS_Product.ProductHeight,ODS_Product.ProductWidth,
ODS_Product.ProductLength,ODS_Product.dtPackageSize1,
ODS_Product.productHeightUOMID,ODS_Product.productWidthUOMID,
ODS_Product.productLengthUOMID,ODS_ProductName.dtProductNameDescription1,
ODS_ProductName.dtProductNameDescription2,ODS_ProductVendor.VendorID,
ODS_dtProductReference.ReferenceNumber
FROM ODS_Product
JOIN ODS_ProductName ON ODS_ProductName.ProductID=ODS_Product.ProductID
and ODS_ProductName.BusinessUnitId=ODS_Product.BusinessUnitId
JOIN ODS_ProductVendor ON ODS_ProductVendor.ProductID=ODS_Product.ProductID
and ODS_ProductVendor.BusinessUnitId=ODS_Product.BusinessUnitId
LEFT JOIN ODS_dtProductReference ON
ODS_dtProductReference.ProductID=ODS_Product.ProductID
and ODS_dtProductReference.BusinessUnitId=ODS_Product.BusinessUnitId
and ODS_dtProductReference.ReferenceID='SRII')
where ODS_Product.ProductID='2602_1487130'
and ODS_Product.BusinessUnitId=6
您正在混合隐式连接和显式连接。这是允许的,但你需要知道如何正确地做到这一点
问题是,显式连接使用JOIN关键字实现的连接优先于隐式连接“逗号”连接,其中连接条件在where子句中指定。这两个是参数,fx可以是p.ProductID='2602_1487130'和p.BusinessUnitId=6您是否可以尝试通过仅查询ODS_产品来隔离问题,以查看参数是否被正确绑定?类似于从ODS_Product p中选择p.ProductID、p.dtGTIN、p.ProductWeight,其中p.ProductID=Thx Ram Singh,但它不起作用,给出了很多很多很多很多行。@user1073857抱歉,我错过了要添加的最后一个连接,请添加最后一个连接,并让我知道它是否适用于ODS_ProductReference表