Solved

SQL Statement Syntax Error

Posted on 2014-03-14
3
412 Views
Last Modified: 2014-03-14
I have a syntax error that is driving ne crazy. The SQL statement below works OK.

Select * FROM [JDE_PRODUCTION].[PRODDTA].[F3111] T1
INNER JOIN [dbo].[xls(GDS-8567-03122-14-01)] T2
On T1.WMDCTO = T2.xlsDcto and T1.WMDOCO = T2.xlsDOCO
WHERE (T1.WMMCU='       22101')


But, this SQL statement has a Syntax error. Anyone out there can help me resolve the issue?

Begin Tran
DELETE FROM [JDE_PRODUCTION].[PRODDTA].[F3111] T1
INNER JOIN [dbo].[xls(GDS-8567-03122-14-01)] T2
On T1.WMDCTO = T2.xlsDcto and T1.WMDOCO = T2.xlsDOCO
WHERE (T1.WMMCU='       22101')
Rollback Tran

Error msg:
Msg 102, Level 15, State 1, Line 2
Incorrect syntax near 'T1'.


I cannot find the bug in the above SQL statement. HELP!

tw
0
Comment
Question by:Tom Winslow
3 Comments
 
LVL 16

Expert Comment

by:DcpKing
Comment Utility
Not connected to a SQL Server right now to try it, but I think this works:

DELETE FROM T1
from [JDE_PRODUCTION].[PRODDTA].[F3111] T1
INNER JOIN [dbo].[xls(GDS-8567-03122-14-01)] T2 
On T1.WMDCTO = T2.xlsDcto and T1.WMDOCO = T2.xlsDOCO
WHERE (T1.WMMCU='       22101')

Open in new window


I'll check it when I get into work :)


hth

Mike
0
 
LVL 142

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 500 total points
Comment Utility
I confirm above idea to work correctly, when deleting with a join, you have to "first" specify which table to delete from, actually. but the syntax has a small issue:
DELETE T1
FROM [JDE_PRODUCTION].[PRODDTA].[F3111] T1
INNER JOIN [dbo].[xls(GDS-8567-03122-14-01)] T2 
On T1.WMDCTO = T2.xlsDcto and T1.WMDOCO = T2.xlsDOCO
WHERE (T1.WMMCU='       22101') 

Open in new window

0
 

Author Closing Comment

by:Tom Winslow
Comment Utility
Thanks!
0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

If you have heard of RFC822 date formats, they can be quite a challenge in SQL Server. RFC822 is an Internet standard format for email message headers, including all dates within those headers. The RFC822 protocols are available in detail at:   ht…
Slowly Changing Dimension Transformation component in data task flow is very useful for us to manage and control how data changes in SSIS.
Using examples as well as descriptions, and references to Books Online, show the different Recovery Models available in SQL Server and explain, as well as show how full, differential and transaction log backups are performed
Via a live example, show how to set up a backup for SQL Server using a Maintenance Plan and how to schedule the job into SQL Server Agent.

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now