Re: Ordering Results
- From: Steve Kass <skass@xxxxxxxx>
- Date: Thu, 25 Aug 2005 01:14:45 -0400
Wes,
Try this:
order by
substring(LocationCode,1,1),
case when substring(LocationCode,1,1) in ('A','C','E','G') then substring(LocationCode,2,2) else null end,
case when substring(LocationCode,1,1) in ('B','D','F','H') then substring(LocationCode,2,2) else null end DESC
You can't put the ASC and DESC keywords inside the case expression, but the problem can still be solved.
Steve Kass Drew University
Wes wrote:
Hi,
I have a result set that returns Loctation Codes.
Each location code is the following format: [Letter][2 Digit Number].
For example, A10 B13 D04
What I would like to do is if the letter is either A, C, E, G then order the results by the letter, then by the 2 digit numbers in ascending order.
If the letter is either B, D, F, H then order the results by the letter, then by the 2 digit numbers in descending order.
So if A, C, E etc then numbers are ascending. If B, D, F etc then numbers are descending.
A result set could look as follows A01 A02 A03 A05 B30 B28 B27 B05 C03 C04 C07 D15 D12 D11
If I could use a case statement within the order by clause, it would solve my problem, but I get an error when attempting to write a case statement within the ORDER BY clause.
Thanks in advance,
Wes.
.
- References:
- Ordering Results
- From: Wes
- Ordering Results
- Prev by Date: Ordering Results
- Next by Date: How to Join a table with Other (result) Tables ? Complex one !
- Previous by thread: Ordering Results
- Next by thread: How to Join a table with Other (result) Tables ? Complex one !
- Index(es):
Relevant Pages
|
|