TOP(1) in update query?

  • Thread starter Thread starter Jesper Fjølner
  • Start date Start date
J

Jesper Fjølner

I'm having problems with "top(1)" part of this SQL. Can I use the TOP word
in an update-query?

UPDATE TOP(1) tblLog SET exittime = #" & Time & "# WHERE username = '" &
CurrentUser & "'"

Running this with db.execute
 
No, you can't.

If you're trying to set the value for a specific row in tblLog, you're going
to have to determine some way of identifying that specific row.
 
If you're trying to set the value for a specific row in tblLog, you're
going
to have to determine some way of identifying that specific row.

I'll figure it out another way. Thanks!
 
How about something similar to the following untested string.

"UPDATE tblLog SET exittime = #" & Time & "# " & _
"WHERE tblLog.PrimaryKey in " & _
"(SELECT Top 1 A.PrimaryKey FROM tblLog " & _
" WHERE Username = '" & CurrentUser & "' " & _
" ORDER BY PrimaryKey)"

You need to set the order by clause to reflect which fields determine which
record should be the first record.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Back
Top