Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 updating

Author  Topic 

notsosuper
Posting Yak Master

190 Posts

Posted - 2005-08-30 : 19:04:51
I have a query that updates

strSQL = "UPDATE customers SET "
strSQL &= "entryid = '" & strtheEntryid & " ' "
strSQL &= "WHERE id =1 "
right now in table id is my primary key field it increments by 1, I want to say get first record instead of saying id = 1, how to do that?

TG
Master Smack Fu Yak Hacker

6065 Posts

Posted - 2005-08-30 : 19:17:17
You'll have to define "first" record with an ORDER BY. Remember, sql doesn't store the data in any particular order.
Here is the sql version, you can either put it in an SP (preferred method) or build the sql yourself in your app as you seem to be doing now.

UPDATE customers SET
entryid @entryid
WHERE id IN
(select top 1 id
from customers
order by ????)


Be One with the Optimizer
TG
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2005-08-31 : 01:08:15
or

UPDATE customers SET
entryid = @entryid
WHERE id =(select min(id) from customers)


Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -