Wednesday, December 07, 2005
« Control-Click + Taskbar = Awesome! | Main | How to NOT dispose a dialog form »

Ken McNamee has been thinking outside the SQL box.  I didn't realize that you can use a "case" statement in the "order by" clause:


DECLARE @orderBy varchar(50)
SET @orderBy = 'LastName'

SELECT
    *
FROM
    Employees
ORDER BY
    CASE
        WHEN @orderBy = 'LastName' THEN LastName
    END,
    CASE
        WHEN @orderBy = 'HireDate' THEN HireDate
    END

For more on this, see his post:
http://blogs.vertigosoftware.com/kenm/archive/2005/12/06/Dynamic_ORDER_BY_Clause.aspx

Wednesday, December 07, 2005 3:58:29 PM (Central Standard Time, UTC-06:00)  #    Disclaimer  |  Comments [0]  |  Related posts:
window.open sizing
RECT vs. Rectangle
Windows XP goes open source... kinda
How to NOT dispose a dialog form
VS Crash Loop
WebBrowser Control Resources

Name
E-mail
(will show your gravatar icon)
Home page

Comment (Some html is allowed: a@href@title, b, blockquote@cite, em, i, strike, strong, sub, super, u)  

Enter the code shown (prevents robots):