Hi Tom,
I can offer you some ideas:
- Run UPDATE below 5 times and return 5 PK's
- Add one more filed to the table and stamp it with session id and then select records with that id. Something like
UPDATE inbox
SET state = 'PROCESSING', stamp = @@SPID
WHERE pk IN
( SELECT TOP 5 pk FROM inbox
WHERE state = 'QUEUED')
SELECT pk FROM inbox
WHERE stamp = @@SPID AND state = 'PROCESSING'
>Sergey, I thought you might be the one to reply to this - thanks!
>
>Originally we were going to extract the TOP 5 rows. How would you
>handle that situation should we decide to go that route?
>
>>You can do this with one UPDATE command
DECLARE @pk uniqueidentifier
>>UPDATE inbox
>> SET @pk = pk, state = 'PROCESSING'
>> WHERE pk IN
>> ( SELECT TOP 1 pk FROM inbox
>> WHERE state = 'QUEUED')
>>
>>SELECT @pk
>>
>>>The code below the line is intended to find the next 'Queued' row in an SQL Server 2000 inbox table, change its status to 'Processing' and then return the primary key to a Visual FoxPro application.
>>>
>>>
>>< snip >
--sb--