Modify SQL result set before returning from stored procedure

Posted by m0sa on Stack Overflow See other posts from Stack Overflow or by m0sa
Published on 2010-02-24T23:56:56Z Indexed on 2010/04/01 15:33 UTC
Read the original article Hit count: 224

I have a simple table in my SQL Server 2008 DB:

Tasks_Table
-id
-task_complete
-task_active
-column_1
-..
-column_N

The table stores instructions for uncompleted tasks that have to be executed by a service.

I want to be able to scale my system in future. Until now only 1 service on 1 computer read from the table. I have a stored procedure, that selects all uncompleted and inactive tasks. As the service begins to process tasks it updates the task_active flag in all the returned rows.

To enable scaleing of the system I want to enable deployment of the service on more machines. Because I want to prevent a task being returned to more than 1 service I have to update the stored procedure that returns uncompleted and inactive tasks.

I figured that i have to lock the table (only 1 reader at a time - I know I have to use an apropriate ISOLATION LEVEL), and updates the task_active flag in each row of the result set before returning the result set.

So my question is how to modify the SELECT result set iin the stored procedure before returning it?

© Stack Overflow or respective owner

Related posts about stored-procedures

Related posts about tsql