Re: Order By - Conditional

From: Wes (anonymous_at_discussions.microsoft.com)
Date: 09/15/04

  • Next message: Hugo Kornelis: "Re: Order By - Conditional"
    Date: Wed, 15 Sep 2004 10:14:33 -0700
    
    

    I have tried the following but with no success...

    ORDER BY CASE WHEN Status > 11 THEN Name END,
    CASE WHEN Status <= 11 THEN Order_ID END

    Is there any other approach I can use?

    Thanks in advance

    >-----Original Message-----
    >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: Hugo Kornelis: "Re: Order By - Conditional"

    Relevant Pages

    • Re: Ghost Icon on Desktop
      ... Tried both of those Wes and still get the same error message. ... > This opens the All Users Desktop folder... ... Had no success at all. ... >>> MANUALLY DELETING STUBBORN FILES ...
      (microsoft.public.windowsxp.customize)
    • Re: basic SQL query
      ... It retrurns either success or failure. ... I wonder how Hugo gets around the need to load the rdbms-dependant drivers ...
      (comp.databases)
    • Re: Advanced Options on Search for Files/Folders
      ... Wes, thanks for the prompt response, but as mentioned in the ... original post, I already tried Kelly's fix without success, that ...
      (microsoft.public.windowsxp.help_and_support)
    • Re: Advanced Options on Search for Files/Folders
      ... Wes, thanks for the prompt response, but as mentioned in the ... original post, I already tried Kelly's fix without success, that ...
      (microsoft.public.windowsxp.general)
    • Re: Advanced Options on Search for Files/Folders
      ... Wes, thanks for the prompt response, but as mentioned in the ... original post, I already tried Kelly's fix without success, that ...
      (microsoft.public.windowsxp.newusers)