Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Incorrect syntax error

Author  Topic 

Damian39
Starting Member

33 Posts

Posted - 2014-11-05 : 15:49:01
Hello all,
I added a sub-query to a temp table that was working prior to me adding the sub-query. Now that I've added the sub-query I am getting an incorrect syntax error with my join. I'm unsure as to what could be causing this. I've checked the query, and I don't have any commas out of place, and I'm pretty sure I have the parenthesis in the correct place, but the code just isn't working. I was hoping someone on this forum might be able to see something I can't.


CREATE TABLE #TMPCSGACCT1 (
[ITEM#] NUMERIC (7,0),
[SUB_ACCT_NO] VARCHAR (MAX),
[CUST_ACCT_NO] VARCHAR (MAX),
[ORDER_NUMB] VARCHAR (MAX)
)
INSERT INTO #TMPCSGACCT1 (ITEM#,SUB_ACCT_NO,CUST_ACCT_NO,ORDER_NUMB)

SELECT ITEM#,
rtrim(ltrim([SUB_ACCT_NO])) as SUB_ACCT_NO,
rtrim(ltrim([CUST_ACCT_NO])) as CUST_ACCT_NO,
rtrim(ltrim([ORDER_NUMB])) as ORDER_NUMB

FROM AuditGroup.dbo.Order_Num_Data3 (NOLOCK)

SELECT A.ITEM#, A.SUB_ACCT_NO, A.CUST_ACCT_NO, A.ORDER_NUMB, B.PRIN_OJB, B.AGNT_OJB,
B.JOB_TYP_OJB, B.COMPL_CDE_OJB, B.LS_CHG_OP_ID_OJB, B.LS_CHG_DTE_OJB

INTO #TMP1C

FROM #TMPCSGACCT1 AS A (NOLOCK) INNER JOIN Vantage.dbo.OJB_JOBS AS B (NOLOCK)

ON A.ORDER_NUMB = B.ORDER_NO_OJB

WHERE B.LS_CHG_DTE_OJB = (SELECT MAX(B.LS_CHG_DTE_OJB) AS LS_CHG_DTE_OJB FROM
Vantage.dbo.OJB_JOBS AS C ON C.LS_CHG_DTE_OJB = B.LS_CHG_DTE_OJB)


GROUP BY A.ITEM#, A.SUB_ACCT_NO, A.CUST_ACCT_NO, A.ORDER_NUMB, B.PRIN_OJB, B.AGNT_OJB,
B.JOB_TYP_OJB, B.COMPL_CDE_OJB, B.LS_CHG_OP_ID_OJB, B.LS_CHG_DTE_OJB

Thank you in advance!

Damian

Bustaz Kool
Master Smack Fu Yak Hacker

1834 Posts

Posted - 2014-11-05 : 16:34:35
You have an "ON" condition in the sub-query but there is not any JOIN being performed. Try changing the "ON" to "WHERE".



No amount of belief makes something a fact. -James Randi
Go to Top of Page
   

- Advertisement -