View previous topic :: View next topic |
Author |
Message |
Catherine Beginner
Joined: 30 Aug 2006 Posts: 32 Topics: 15 Location: Chennai
|
Posted: Sat Nov 25, 2006 5:13 am Post subject: Ordering a specific coloumn based on the values i specify |
|
|
I have a particular coloumn in my table named "STATUS" . This is a numeric field with values ranging as 10,20,30,40,50.
I donot want this coloumn either in ascending or descending order.
I want it in the following order ( 30, 10, 50, 20, 40). How shall i specify it in my order by clause? |
|
Back to top |
|
|
dbzTHEdinosauer Supermod
Joined: 20 Oct 2006 Posts: 1411 Topics: 26 Location: germany
|
Posted: Sat Nov 25, 2006 6:53 am Post subject: |
|
|
you can use a CASE to set another selected column/:Host-variable based on your STATUS and ORDER BY the CASEd column.
or
using case, change the status from 30 to 'A 30', 10 to 'B 10' etc... _________________ Dick Brenholtz
American living in Varel, Germany |
|
Back to top |
|
|
Catherine Beginner
Joined: 30 Aug 2006 Posts: 32 Topics: 15 Location: Chennai
|
Posted: Sat Nov 25, 2006 7:02 am Post subject: |
|
|
Dick,
thks a lot dick!! Could You Plz post the exact Case syntax i should give in the order by clause . I get an error while executing the query |
|
Back to top |
|
|
kolusu Site Admin
Joined: 26 Nov 2002 Posts: 12376 Topics: 75 Location: San Jose
|
Posted: Sat Nov 25, 2006 8:51 am Post subject: |
|
|
Catherine,
Try this untested sql
Code: |
SELECT Z.STATUS
FROM (SELECT STATUS
,CASE STATUS
WHEN 30 THEN 1
WHEN 10 THEN 2
WHEN 50 THEN 3
WHEN 20 THEN 4
WHEN 40 THEN 5
ELSE 9 END AS SR_NO
FROM Table) Z
ORDER BY SR_NO
;
|
Hope this helps...
Cheers
Kolusu _________________ Kolusu
www.linkedin.com/in/kolusu |
|
Back to top |
|
|
Catherine Beginner
Joined: 30 Aug 2006 Posts: 32 Topics: 15 Location: Chennai
|
Posted: Tue Nov 28, 2006 5:43 am Post subject: |
|
|
Thks Kolusu.. I got it!!! |
|
Back to top |
|
|
|
|