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

  • Home
  • SEARCH
  • 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 6746955
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T12:23:02+00:00 2026-05-26T12:23:02+00:00

We have a system that processes records by a priority number in a table.

  • 0

We have a system that processes records by a “priority” number in a table. We define the priority by the contents of the table, e.g.

UPDATE table
SET priority=3
WHERE processed IS NULL

UPDATE table
SET priority=2
WHERE balance>50

UPDATE table
SET priority=1
WHERE value='blah'

(please ignore the fact that there could be ‘overlaps’ between priorities 🙂 )

This works fine – the table is processed in priority order, so all the rows where the column “value” is ‘blah’ are worked first.

I’ve been given the task of adding an option to order the records by a definable “weight”. For example, we’d like 50% of the processing to be priority 1, 25% priority 2 and 25% priority 3. Therefore, from the above, in every 100 records 50 of them would be ones where “value” is ‘blah”, 25 of them would be where “balance” is greater than 50 etc.

I’m trying to figure out how to do this: some kind of weighted incrementing value for “priority” would seem to be the best way, but I can’t get my head around how to code this. Can anyone help please?

EDIT: Apologies, should have said: this is running on MSSQL 2008

  • 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-26T12:23:03+00:00Added an answer on May 26, 2026 at 12:23 pm

    General idea is to collect tasks into buckets, divided on border of whole numbers:

    select
      task_id
    from (  
      select 
        task_id, 
        ((task_priority_order - 1) / task_priority_density) as task_processing_order
      from (
        select
          t.task_id                                            as task_id, 
          t.priority                                           as task_priority, 
          row_number() 
            over (partition by t.priority order by t.priority) as task_priority_order,
          case
            when t.priority = 3 then 50
            when t.priority = 2 then 25
            when t.priority = 1 then 25
          end                                                  as task_priority_density
        from
          table t
      )
    )
    order by task_processing_order
    

    In the diapason from 0.0 to 0.(9) we got 100 records constructed from first 50 records with priority 3, first 25 records with priority 2 and first 25 records with priority 1.

    The next diapason from 1.0 to 1.(9) represents next bucket of records.

    If no more tasks with some value of priority then remaining tasks will be placed in buckets in same ratio. E.g. if not enough tasks with priority 3 then remaining tasks will be arranged with ratio of 50/50.

    task_id – some surrogate key for task identification.

    P.S. Sorry, I can’t test this query now, so any syntax correction very appreciated.

    Update: Query syntax corrected according to comments.

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

Sidebar

Related Questions

I have a simple Tray icon program that opens a site using System.Diagnostics.Process.Start(URL) And
We have system here that uses Java JNI to call a function in a
I have a system that combines the best and worst of Java and PHP.
I have a system that uses a meta refresh to a logout page, which
I have a system that creates an order and that order can be billed
We have a system that has a Mysql database with about 2Gigs of data.
I have a system that compares fiscal year up to the current date to
I have a system that takes dynamic data, puts it in HTML for layout
I have big system that make my system crash hard. When I boot up,
I have a system that runs like this: main.exe runs sub.exe runs sub2.exe and

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.