Incorrect syntax near outer join in sql server - 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

Related

3061 Too few parameters.Expected1

I am getting the Error two few parameters Expected 1.For the below query which I am using in MS Access vba code .I am able to point that Where clause is the reason I am getting this error.But not sure why.
strSQL ="SELECT Count(*) FROM Table_1 INNER JOIN Table_2 ON (Table_2.[F6] = Table_1.[Column1]) WHERE ( (Table_1.[Table1_Date])> DateAdd(month,-1,Date()) );"
Set rs = MyDB.OpenRecordset(strSQL)

Querying a server level trigger definition in SQL Server

I am trying to query the definition text of a server-level trigger. More specifically, trying to query the definition from within a user-defined stored procedure. Because the trigger is saved on the server level, the normal ways do not seem to work.
What I have tried:
1)
sp_helptext: The scope is wrong and I get the message:
Msg 15009, Level 16, State 1, Procedure sp_helptext, Line 54
The object 'myTrigger' does not exist in database 'master' or is invalid for this operation.
2) SELECT OBJECT_DEFINITION (OBJECT_ID(N'myTrigger)) AS ObjectDefinition;:
This returns NULL. I replaced "myTrigger" with the object id from sys.server_triggers. This also returns NULL.
3)
SELECT
name,
s.Definition
FROM
sys.server_triggers t
INNER JOIN sys.sql_modules s
ON t.object_id = s.object_id
WHERE name = 'myTrigger'
The object doesn't exist in sys.sql_modules
Try this
SELECT ssmod.definition AS [Definition]
FROM master.sys.server_triggers AS tr
LEFT OUTER JOIN master.sys.server_assembly_modules AS mod ON mod.object_id = tr.object_id
LEFT OUTER JOIN sys.server_sql_modules AS ssmod ON ssmod.object_id = tr.object_id
WHERE (tr.parent_class = 100) and (tr.name = 'MyTriggerName')

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;

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

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).

SQL Statement with OR never finishes executing, freezes SQL Database

I have an SQL statement
SELECT dbo.sem_computer.COMPUTER_NAME,dbo.sem_computer.COMPUTER_ID,
[IP_ADDR1_TEXT],dbo.sem_computer.COMPUTER_DOMAIN_NAME, [ID],dbo.SEM_AGENT.AGENT_VERSION
FROM sem_computer, [dbo].[V_SEM_COMPUTER], IDENTITY_MAP, SEM_CLIENT,dbo.SEM_AGENT
WHERE [dbo].[V_SEM_COMPUTER].COMPUTER_ID = SEM_COMPUTER.COMPUTER_ID and dbo.IDENTITY_MAP.ID = dbo.SEM_CLIENT.GROUP_ID
and dbo.SEM_COMPUTER.COMPUTER_ID = dbo.SEM_CLIENT.COMPUTER_ID
AND dbo.SEM_COMPUTER.COMPUTER_ID = dbo.SEM_AGENT.COMPUTER_ID
AND NAME = 'My Company\Default Group'
OR NAME = 'My Company\Bronx'
order by [IP_ADDR1_TEXT]
That executed indefinitely and even freezes the SQL server when I tried to copy and paste this code.
If I remove the
OR NAME = 'My Company\Bronx'
then the the SQL statement executes just fine
We are using SQL Server 2008
Thank you
I think this whole problem becomes a lot clearer if you write ANSI-Compliant T-SQL. So rather than have your able join conditions in the WHERE clause, you have something like:
SELECT
dbo.sem_computer.COMPUTER_NAME
, dbo.sem_computer.COMPUTER_ID
, [IP_ADDR1_TEXT]
, dbo.sem_computer.COMPUTER_DOMAIN_NAME
, [ID]
, dbo.SEM_AGENT.AGENT_VERSION
FROM
sem_computer AS COM
INNER JOIN
[dbo].[V_SEM_COMPUTER] AS V
ON
COM.COMPUTER_ID = V.COMPUTER_ID
INNER JOIN
dbo.SEM_CLIENT AS CLI
ON
COM.COMPUTER_ID = CLI.COMPUTER_ID
INNER JOIN
dbo.SEM_AGENT AS AGT
ON
COM.COMPUTER_ID = AGT.COMPUTER_ID
INNER JOIN
IDENTITY_MAP AS IM
ON
CLI.GROUP_ID = IM.ID
...
Then your WHERE clause does what it is designed to do, which is filter your data. This becomes, as suggested earlier
WHERE
NAME IN('My Company\Default Group','My Company\Bronx')
The performance problem you had was, as pointed out, you were getting a cross join of all tables. But I think you would have noticed this if you write your joins in an ANSI compliant way.
I hope that helps.
Ash
OR NAME IN('My Company\Default Group','My Company\Bronx')
Should work.
When you have the AND NAME = 'My Company\Default Group'
OR NAME = 'My Company\Bronx' not in parentheses or using an IN clause, it means that it will get everything where the OR condition is satisfied, ignoring all of the other conditions.

Resources