Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 634383
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T20:17:23+00:00 2026-05-13T20:17:23+00:00

I have a simple table in my SQL Server 2008 DB: Tasks_Table -id -task_complete

  • 0

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?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T20:17:24+00:00Added an answer on May 13, 2026 at 8:17 pm

    This is the typical dequeue pattern, is implemented using the OUTPUT clause and and is described in the MSDN, see the Queues paragraph in OUTPUT Clause (Transact-SQL):

    UPDATE TOP(1) Tasks_Table WITH (ROWLOCK, READPAST)
     SET task_active = 1
     OUTPUT INSERTED.id,INSERTED.column_1, ...,INSERTED.column_N 
     WHERE task_active = 0;
    

    The ROWLOCK,READPAST hint allows for high throughput and high concurency: multiple threads/processed can enqueue new tasks while mutliple threads/process dequeue tasks. There is no order guarantee.

    Updated

    If you want to order the result you can use a CTE:

    WITH cte AS (
      SELECT TOP(1) id, task_active, column_1, ..., column_N
      FROM Task_Table WITH (ROWLOCK, READPAST)
      WHERE task_active = 0
      ORDER BY <order by criteria>)
    UPDATE cte
      SET task_active = 1
    OUTPUT INSERTED.id, INSERTED.column_1, ..., INSERTED.column_N;
    

    I discussed this and other enqueue/dequeue techniques on the article Using Tables as Queues.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 315k
  • Answers 315k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer You're looking for the :gt selector: $('.facet').each(function() { var ul… May 13, 2026 at 11:19 pm
  • Editorial Team
    Editorial Team added an answer I was able to work around the issue by doing… May 13, 2026 at 11:19 pm
  • Editorial Team
    Editorial Team added an answer public class Program { static void Main(string[] args) { ParserBase… May 13, 2026 at 11:19 pm

Related Questions

Suppose I want entries in the table Regions to have a type, e.g. a
If I have a table that (among other columns) has two DATETIME columns, how
My SQL Express database has run out of room so I'm migrating my heavy
For my application I have to support update scenarios and the database might be
I have some extended property column descriptions in a SQL Server 2008 database, and

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.