ORDER BY - DB2 SQL

I have a simple SQL, in DB2...

SELET EVAL_CODE
FROM DB2DBA.TEST_CODE

The values of EVAL_CODE are 'T','C','O','P','Z','D'

if I add "ORDER BY EVAL_CODE DESC" or "ORDER BY EVAL_CODE ASC" to the SQL, the result will be like... 'C','D','O','P','T','Z' or 'Z','T','P','O','D','C'

Is there a way that I can order the result set as 'Z','O','P','C','D','T'?

Thanks,
txman35Asked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

carsRSTCommented:
You would have to add another field, associate the order you want to the letters, and order by the new field.

EVAL_CODE     EVAL_CODE_ORDER (new field)
   Z                              1
   O                              2
   P                              3
(on down)
0
carsRSTCommented:
Sorry - another idea hit me.  Not in a position to try but think this will work.

Use a Case/When in your order by clause...

SELET EVAL_CODE
FROM DB2DBA.TEST_CODE
order by
case when EVAL_CODE = 'Z' then 1
case when EVAL_CODE = 'O' then 2
...
END

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
k_murli_krishnaCommented:
Try this:

SELET EVAL_CODE
FROM DB2DBA.TEST_CODE
ORDER BY
CASE EVAL_CODE WHEN 'Z' THEN 1
                             WHEN 'O' THEN 2
                             WHEN 'P' THEN  3
                             WHEN 'C' THEN 4
                             WHEN 'D' THEN 5
                             WHEN 'T' THEN 6
END;

You can try give an alias to the CASE using END EVAL_CODE_ORDER OR END AS EVAL_CODE_ORDER.
0
txman35Author Commented:
Thank you very much for all your help.  It works great.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
DB2

From novice to tech pro — start learning today.