We have several thousand job numbers stored in a SQL Server database, and I'd like to be able to derive what 1000's or 100's range they fall into for purposes of grouping in a third party application, which is integrated with our jobs list.
How can I extract the 1000's group that each job number would belong to in a column in my query's result set?
Examples: I would like for my output to be:
JOB_NUMBER JOB_GROUP
678 0-999
679 0-999
1517 1000-1999
2011 2000-2999
2150 2000-2999
...etc.
If job_number is an integer, you can use this:
select job_number,
convert(varchar(10), job_number / 1000 * 1000)
+ '-'
+ convert(varchar(10), job_number / 1000 * 1000 + 999) Range
from whatever
You could use a CASE expression:
SELECT
JOB_NUMBER,
JOB_GROUP = CASE
WHEN JOB_NUMBER < 1000 THEN '0-999'
WHEN JOB_NUMBER < 2000 THEN '1000-1999'
WHEN JOB_NUMBER < 3000 THEN '2000-2999'
END
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With