Solved

UPDATE TOP in MS Access

Posted on 2011-03-10
4
460 Views
Last Modified: 2012-05-11
I'm getting: "Syntax error in UPDATE statement" in Access 2007 for the following:

DoCmd.RunSQL "UPDATE TOP(1) [Team 01] SET FirstName = 'Carl', LastName = 'Crawford', Rank = 3, Pos1 = 'OF', Pos2 = '', Pos3 = '' WHERE Position = 'OF'"

The following works but updates too many records:

DoCmd.RunSQL "UPDATE [Team 01] SET FirstName = 'Carl', LastName = 'Crawford', Rank = 3, Pos1 = 'OF', Pos2 = '', Pos3 = '' WHERE Position = 'OF'"

[Team 01] has multiple (3) records where Position = 'OF'.  The second statement above updates all 3 records.   I only want to updated one of those records when Carl Crawford is selected.
0
Comment
Question by:CMCONE
4 Comments
 
LVL 29

Expert Comment

by:Paul Jackson
ID: 35102187
If you only want to update the carl crawford record why are you not including that in the where clause:
DoCmd.RunSQL "UPDATE [Team 01] SET FirstName = 'Carl', LastName = 'Crawford', Rank = 3, Pos1 = 'OF', Pos2 = '', Pos3 = '' WHERE FirstName = 'Carl' AND LastName = 'Crawford' AND Position = 'OF'"

0
 
LVL 75

Expert Comment

by:Anthony Perkins
ID: 35105516
>>Zone: MS SQL Server<<
If you are using MS Access than you had best post in that zone.  MS Access uses a different SQL dialect.
0
 
LVL 1

Accepted Solution

by:
infochip earned 500 total points
ID: 35111442

I believe on sql server Transact Sql allows the TOP command in non-select statements.  standard sql does not.  You have to do something like this


SQL = "delete T1 from "
SQL = SQL & " (Select top " & NumberToDelete & " * from qryParserEmaildateAscending where " & sqlCondition & ") T1"
0

Featured Post

Back Up Your Microsoft Windows Server®

Back up all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Question has a verified solution.

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

As tax season makes its return, so does the increase in cyber crime and tax refund phishing that comes with it
Preparing an email is something we should all take special care with – especially when the email is for somebody you may not know very well. The pressures of everyday working life stacked with a hectic office environment can make this a real challen…
Basics of query design. Shows you how to construct a simple query by adding tables, perform joins, defining output columns, perform sorting, and apply criteria.
Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…

790 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