Re: Order By - Conditional
From: Hugo Kornelis (hugo_at_pe_NO_rFact.in_SPAM_fo)
Date: 08/13/04
- Next message: Roy Dean Leighton Jr.: "Data from last transaction needed in another table"
- Previous message: Wes: "Order By - Conditional"
- In reply to: Wes: "Order By - Conditional"
- Messages sorted by: [ date ] [ thread ]
Date: Fri, 13 Aug 2004 14:32:34 +0200
On Fri, 13 Aug 2004 05:04:53 -0700, Wes wrote:
>I wish to include a condition in my order by statement.
>
>i.e. If the value of Field X > Y then Order by Field X,
>else Order by Field Z.
>
>I have tried inserting a select case but i cannot get it
>to work
>
>Here is an extract from the table
>Order_ID Status Name
>50 10 Michael
>51 10 John
>52 10 Peter
>53 20 Adam
>54 20 Bruce
>
>The condition I would like to apply is as follows:
>If Status is greater than 11, Order by Name, else order by
>Order_ID
>
>Any help wpuld be greatly appreciated
Hi Wes,
Something like this?
ORDER BY Status,
CASE WHEN Status > 11 THEN Name END,
CASE WHEN Status <= 11 THEN Order_ID END
Best, Hugo
-- (Remove _NO_ and _SPAM_ to get my e-mail address)
- Next message: Roy Dean Leighton Jr.: "Data from last transaction needed in another table"
- Previous message: Wes: "Order By - Conditional"
- In reply to: Wes: "Order By - Conditional"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|
|