I'm a newbie for SQL Server. Please help me out with my below problem.
I've a table as below,
Job Quantity Status
1 100 OK
2 400 HOLD
3 200 HOLD
4 450 OK
I would like to write a query now in such a way that all the Jobs with Quantity equal to or more than 400 with status OK would appear first then Jobs with Quanitty equal to or more than 400 with status HOLD. Then all the Jobs with Quantity less than 400 with Status OK would appear and after that Jobs with quantity less than 400 with status HOLD should appear.
Here's how my result should appear. (Sorry for the above confusing paragraph)
Job Quantity Status
4 450 OK
2 400 HOLD
1 100 OK
3 200 HOLD
How do I do this? Some one please help me out
SELECT Job, Quantity, Status
FROM myTable
ORDER BY CASE WHEN Quantity >= 400 AND Status = 'OK' THEN 1
WHEN Quantity >= 400 AND Status = 'Hold' THEN 2
WHEN Status = 'OK' THEN 3
ELSE 4
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