using switch statements

  • Kinda dud question, my apologies - anyways you help will be appreciated, I want to  optimize a query  like :

     

     

    if @parameter = 'abc'

    select a.x, b.y.c.z

    from tbl1 a,

    tbl2 b,

    tbl3 c

    {  join statements }

     

    order by a.x, b.y

    if  @parameter = 'abc'

    select a.x, b.y.c.z

    from tbl1 a,

    tbl2 b,

    tbl3 c

    {  join statements }

     

    order by a.x, c.z

    etc..etc

     

    Instead of repeating the code, how can i utilize something like a "switch" for my order by clause..

     

     

    Thx.

     

     

  • You can use CASE.

    BOL has some examples on this

    --
    Frank Kalis
    Microsoft SQL Server MVP
    Webmaster: http://www.insidesql.org/blogs
    My blog: http://www.insidesql.org/blogs/frankkalis/[/url]

Viewing 2 posts - 1 through 1 (of 1 total)

You must be logged in to reply to this topic. Login to reply