468,257 Members | 1,480 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,257 developers. It's quick & easy.

db2 CASE statement in ORDER BY clause

Hi all !

This is my first post here. I am totally new to db2 and last night I faced with this problem:

I want to order my query results by different columns in ORDER BY clause using CASE statement as follows:

DECLARE cursor1 CURSOR WITH RETURN FOR
.....
....
.....
ORDER BY( CASE WHEN ORDER_MODE = '1' THEN 2 ELSE 5 END )

Of course this does not work (I don't know why ). When I write:

ORDER BY( CASE WHEN ORDER_MODE = '1' THEN 5 ELSE 5 END )

This also does not work.

When I write:

ORDER BY ( 5 )

It's working fine, but there is no CASE so it;s not my intention.

Does anybody knows what can be wrong with my statement ?
Thanks for help in advance.
Aug 25 '07 #1
0 1605

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

1 post views Thread by mirth | last post: by
3 posts views Thread by A.V.C. | last post: by
3 posts views Thread by Bryan | last post: by
8 posts views Thread by Jeff Gilbert | last post: by
7 posts views Thread by mandible | last post: by
2 posts views Thread by iulian.ilea | last post: by
10 posts views Thread by Sharif Islam | last post: by
5 posts views Thread by Sascha.Moellering | last post: by
reply views Thread by kermitthefrogpy | last post: by
reply views Thread by zattat | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.