I have a table with following values
OperationCode OperationDesc OperationOrder
Repl Remove 1
R&I Remove 1
Ovrh Remove 1
Refn Prep 1
Repl Replace 2
R&I Install 2
Ovrh Install 2
Refn Paint 2
I want to write a query to get following result order. See in OperationOrder Column
OperationCode OperationDesc OperationOrder
Repl Remove 1
Repl Replace 2
R&I Remove 1
R&I Install 2
Ovrh Remove 1
Ovrh Install 2
Refn Prep 1
Refn Paint 2
I am using sql server 2005.
Here is SQLFiddel Demo
Below is the Sample Query Which You can try
Looks like you want to use
ORDER BY
:IF you need a fixed order of the "OperationCode" a.k.a:
Repl < R&I < Ovrh < Refn
"OperationCode = 'Repl'" will return a 0/1 and if you order it with DESC this will put, 'Repl' values first end everything else after that.
I think you want
as it looks like your OperationId has changed order in each result set and therefore must be an auto-generated number