The multi-part identifier "p.ProductID" could not be bound - sql-server

I have some SQL which executes fine on mssql platform, but we I executes it from a switch yard camel flow (SQL-binding) it do not work.
The sql is
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=#
The message is
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.
Any idea why?

as per my knowledge, you cannot use and in Join clause. please try by removing the and part from join statements.
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=#
I am not sure, but it might help you.

Found a solution to it. The problem was the sql drivers prepared statement thingy. It could not interprete the "p.productId" for some reason, so when i removed all Aliases from the SQL it worked (But I dont know why):
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

You are mixing implicit joins with explicit joins. That is allowed, but you need to be aware of how to do that properly.
The thing is, explicit joins (the ones that are implemented using the JOIN keyword) take precedence over implicit ones (the 'comma' joins, where the join condition is specified in the WHERE clause).

Related

ODBC call failed. The multipart identifier "(tablename)" could not be bound. (#4104)

This query doesnt work when i run this query with tables from sql server as linked back end. But works just fine when tables are from linked ms access back end.
I think it has something to do with the join clause.
SELECT qry_Product_Warehouse.Warehouse_ID, qry_Product_Warehouse.Product_ID,
CDbl(Nz(IIf(IsNull([tbl_Product_Quantity].[Stock_Recount_Date]),
Sum([qry_Product_Transaction].[qty]),
[tbl_Product_Quantity].[Stock_Recount_Quantity]+Sum(IIf([qry_Product_Transaction].[Date]>[tbl_product_quantity].[Stock_Recount_Date],[qry_Product_Transaction].[Qty],0))),0)) AS Current_Qty
FROM (qry_Product_Warehouse
LEFT JOIN qry_Product_Transaction ON (qry_Product_Warehouse.Warehouse_ID = qry_Product_Transaction.Location)
AND (qry_Product_Warehouse.Product_ID = qry_Product_Transaction.Product))
LEFT JOIN tbl_Product_Quantity ON (qry_Product_Warehouse.Product_ID = tbl_Product_Quantity.Product)
AND (qry_Product_Warehouse.Warehouse_ID = tbl_Product_Quantity.Warehouse)
GROUP BY qry_Product_Warehouse.Warehouse_ID, qry_Product_Warehouse.Product_ID, tbl_Product_Quantity.Stock_Recount_Quantity, tbl_Product_Quantity.Stock_Recount_Date;

Incorrect syntax near outer join in sql server

I am trying this query to fetch data from two table. I am getting the error on join.
select
bundlechecklist.Bundle_TXN_ID,
documentchecklist.Bundle_TXN_ID,
documentchecklist.Doc_Type_Name
from
bundle_checklist_txn bundlechecklist
outer join
Document_Checklist_TXN documentchecklist on
documentchecklist.Bundle_TXN_ID = bundlechecklist.Bundle_TXN_ID
where
bundlechecklist.originating_tran_id = "AMD1256" and bundle_name = "Line"
Please help me in fixing the error

Joining three worksheets in Report Builder query using ODBC connection to spreadsheet

This may be a longshot, but I was trying to join three tabs of a spreadsheet in a report builder 3.0 data source. Since I know I can't join two data sets in a table, I'm trying to format the original datasource query.
It works if I join two tabs; all fields of the two tabs are available. When I add a third, it errors out with
"ERROR [42000] ... Syntax error (missing operator) in query expression"
This works:
SELECT LESigner.Name, AcctSigner.Account
FROM [LESigner$] LESigner
JOIN [SignersByAccount$] AcctSigner
on LESigner.AccountCode = AcctSigner.Account
This does not
SELECT LESigner.Name, AcctSigner.Account, LE.ID
FROM [LESigner$] LESigner
JOIN [SignersByAccount$] AcctSigner
on LESigner.AccountCode = AcctSigner.Account
JOIN [LegalEntity$] LE
on LE.ID = LESigner.ID
I appreciate any thoughts or advice.
other relevant facts:
Report builder 3.0
Excel 2013
Thanks,
-bc
Try putting parenthesis around JOINs.
Per: Syntax error (missing operator) in query expression
SELECT LESigner.Name, AcctSigner.Account, LE.ID
FROM ([LESigner$] LESigner
JOIN [SignersByAccount$] AcctSigner
on LESigner.AccountCode = AcctSigner.Account )
JOIN [LegalEntity$] LE
on LE.ID = LESigner.ID

microsoft sql select query from multiple tables

This query is working in mysql but is not working in microsoft sql server management studio 2008, can someone help me out?
SELECT DISTINCT C.firstname,C.lastname,QC.category_name,QR.cid,QR.catid,QR.rhid
FROM cms_question_report QR,
cms_clients C,
cms_questioncategory QC ,
cms_reporthistory RH
WHERE C.id=QR.cid
AND QR.rhid=RH.id
AND QR.catid='3'
AND QR.catid=QC.id
I am getting the error: Invalid object name cms_question_report
SELECT DISTINCT C.firstname,C.lastname,QC.category_name,QR.cid,QR.catid,QR.rhid
FROM cms_question_report QR
left join cms_clients C
on C.id=QR.cid
left join cms_questioncategory QC
on QR.catid=QC.id
and QR.catid='3'
left join cms_reporthistory RH
on QR.rhid=RH.id
I think this should do
specify Normally it happens when you have specific schema and you don't specify it for example:
Replace dbo. with your schema and/or type your database name
SELECT DISTINCT C.firstname,C.lastname,QC.category_name,QR.cid,QR.catid,QR.rhid
FROM databasename.dbo.cms_question_report QR,
databasename.dbo.cms_clients C,
databasename.dbo.cms_questioncategory QC ,
databasename.dbo.cms_reporthistory RH
WHERE C.id=QR.cid
AND QR.rhid=RH.id
AND QR.catid='3'
AND QR.catid=QC.id

SQL Switch/Case/between in where clause

I tried searching around but couldn't find anything that would help me out.
SELECT COL1,* FROM TAB1 A
JOIN TAB2 b ON A.ID=B. ID
INNER JOIN TAB3 C ON C.AsOf=A.AsOf
WHERE
B.AsOf BETWEEN
(
CASE WHEN C.DayOfWeek = 7 AND C.IsCalendarMonthEnd = 'Y'
THEN DATEADD(dd,-1,C.PreviousCalendarDay) AND DATEADD(dd,+1,C.AsOf)
END
)
i am getting error like 'Incorrect syntax near the keyword 'AND''
i need find dates between dates basid on case statment
if possible?
Unfortunately, error messages from Oracle in particular (you don't say which database server you're using) can be maddeningly unclear about where the error lies.
The problem is here:
JOIN TAB2 b ON A.ID=B. ID AND
INNER JOIN TAB3 C ON C.AsOf=A.AsOf
You don't want the AND there. It's a syntax error.
There's an issue with your WHERE clause. You can't specify both bounds of the BETWEEN operator in CASE in one go. Possibly what you meant it to be like is this:
…
WHERE C.DayOfWeek = 7
AND C.IsCalendarMonthEnd = 'Y'
AND B.AsOf BETWEEN DATEADD(dd,-1,C.PreviousCalendarDay) AND DATEADD(dd,+1,C.AsOf)

Resources