Keeping DB Table sorted using multi-field formula (Microsoft SQL Server)

Posted by user298167 on Stack Overflow See other posts from Stack Overflow or by user298167
Published on 2010-03-20T21:08:38Z Indexed on 2010/03/21 0:41 UTC
Read the original article Hit count: 214

Filed under:
|
|
|

I have a JOB table, with two interesting columns:

  • Creation Date
  • Importance (high - 3, medium 2, low - 1).

A JOB record's priority calculated like this:

Priority = Importance * (time passed since creation)

The problem is, every time I would like to pick 200 jobs with highest priority, and I don't want to resort the table. Is there a way to keep rows sorted?

I was also thinking about having three tables one for High, Medium and Low and then sort those by Creation Date.

© Stack Overflow or respective owner

Related posts about sql

Related posts about tsql