Solved

UPDATE TOP in MS Access

Posted on 2011-03-10
4
404 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

Get up to 2TB FREE CLOUD per backup license!

An exclusive Black Friday offer just for Expert Exchange audience! Buy any of our top-rated backup solutions & get up to 2TB free cloud per system! Perform local & cloud backup in the same step, and restore instantly—anytime, anywhere. Grab this deal now before it disappears!

Join & Write a Comment

In the previous article, Using a Critera Form to Filter Records (http://www.experts-exchange.com/A_6069.html), the form was basically a data container storing user input, which queries and other database objects could read. The form had to remain op…
Regardless of which version on MS Access you are using, one of the harder data-entry forms to create is one where most data from previous entries needs to be appended to new records, especially when there are numerous fields and records involved.  W…
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.
With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…

758 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

20 Experts available now in Live!

Get 1:1 Help Now