I have a script that processes queued records in a SQL table in SQL Server 2000. I now need to add additional instances of my script to process their own subset of the queued records in the table.
How can I query the table within each instance so that each instance will return a subset of rows that never overlap with each other?
I could query the id row for odd numbers in one process and even numbers in another, but I’ll need to add more than 2 instances eventually.
CREATE TABLE requests (
id int IDENTITY(1,1) NOT NULL,
requestor VARCHAR(50),
status INT,
created DATETIME,
queuetime DATETIME
)
The existing query for the single instance is:
SELECT * FROM requests WHERE status = 1 ORDER BY queuetime
Based, on your odd/even solution, it sounds like it doesn’t matter what sequence the requests are processed. So, maybe you could do something like this.
The 3 in the second condition represents the number of processes. The number 2 indicates the 2nd process.