Solved

Do you know why I get the syntax error Msg 102, Level 15 while using SQL Server 2005?

Posted on 2011-03-24
1
403 Views
Last Modified: 2012-06-21
I am developing an Access application using Access 2003 with an ADP type file.

Do you now why the following statement causes a syntax error using SQL Server 2005?
The syntax error is as follows:

Msg 102, Level 15, State 1, Line 2
Incorrect syntax near 'A'

delete
from dbo.tblGetDocumentAttributes A
where exists (select 1 from dbo.tblGetDocumentAttributes B
                      where B.Account = A.Account
                      and B.DocumentDate = A.DocumentDate                    
                      and B.MailID < A.MailID)
----------------------------------------------------------------------------

     MailID   Account   DocumentDate                     ScanDate    Amount.
 1   A34R   45677      2010-08-31 00:00:00.000
 2   B78E    45677      2010-09-30 00:00:00.000
 3   R546    45677      2011-01-31 00:00:00.000
 4   G555    45677      2011-01-31 00:00:00.000
 5   C645    86453      2010-08-31 00:00:00.000
 6   E567    86453      2010-09-30 00:00:00.000
 7   R546    86543      2011-01-31 00:00:00.000
 8   R555    86543      2011-02-28 00:00:00.000


My goal was to delete any records from this table in which
any particular account has multiple records with the same documentdate and in these instances just keep the record with the higher MailID (type nvarchar) ?

So in the example above, the 4th record would be deleted because it has the same
account plus documentdate as record 3 but record 4 has the lower ranking MailID.
0
Comment
Question by:zimmer9
1 Comment
 
LVL 32

Accepted Solution

by:
ewangoya earned 500 total points
ID: 35211959


delete
from dbo.tblGetDocumentAttributes
where exists (select 1 from dbo.tblGetDocumentAttributes B
                      where B.Account = dbo.tblGetDocumentAttributes.Account
                      and B.DocumentDate = dbo.tblGetDocumentAttributes.DocumentDate                    
                      and B.MailID < dbo.tblGetDocumentAttributes.MailID
0

Featured Post

U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

by Mark Wills Attending one of Rob Farley's seminars the other day, I heard the phrase "The Accidental DBA" and fell in love with it. It got me thinking about the plight of the newcomer to SQL Server...  So if you are the accidental DBA, or, simp…
Introduction This article will provide a solution for an error that might occur installing a new SQL 2005 64-bit cluster. This article will assume that you are fully prepared to complete the installation and describes the error as it occurred durin…
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

810 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