Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

SQL Update Statement for first N rows?

Status
Not open for further replies.

rstrong

Programmer
Jun 22, 2007
15
US
Hey

I am having some trouble writing an SQL command. I need to set a field in the first N entries of a table. I thought it would be something like this:

UPDATE TOP N table SET field1 = 'whatever'

but it doesn't work. It seems I can't use TOP with the UPDATE statement. Is there something else I can use?
Thanks.
 
A starting point:
UPDATE table SET field1 = 'whatever'
WHERE PrimaryKey In (SELECT TOP N PrimaryKey FROM table ORDER BY 1)

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top