all groups > sql server (microsoft) > september 2004 >
You're in the

sql server (microsoft)

group:

how to: update top 1


how to: update top 1 R. van Laake
9/9/2004 1:04:50 PM
sql server (microsoft):
Hi there,

On SQLServer 2000 , I want to do this: select randomly any unhandled
customer from a table, and before doing anything else mark that customer as
"being handled" (so my collegue won't begin handling the same customer).

Right now I am using:

UPDATE tbl_customers SET col_handledby='Ray' WHERE col_id IN
(SELECT TOP 1 col_id FROM tbl_customers WHERE col_handledby IS NULL ORDER
BY col_telephonenumber)


I would like a more simple query such as:

UPDATE TOP 1 tbl_customers ORDER BY col_telephonenumber
SET col_handledby='Ray' WHERE col_handledby IS NULL

Is it possible to make that easier query?

Thanks,
Ray

Re: how to: update top 1 David Portas
9/9/2004 10:37:55 PM
You can try this:

UPDATE tbl_customers
SET col_handledby = 'Ray'
WHERE col_id =
(SELECT TOP 1 col_id
FROM tbl_customers
WHERE col_handledby <> 'Ray'
OR col_handledby IS NULL
ORDER BY NEWID())

--
David Portas
SQL Server MVP
--

Re: how to: update top 1 R. van Laake
9/10/2004 1:55:35 PM
OK, will try, thanks!

[quoted text, click to view]

AddThis Social Bookmark Button