order by CASE

  • Hi everyone,

    I am trying to use order by and CASE to avoid using dynamic sql in stored procs.

    when i use

    order by

    case when x then col1

    case when y then col2

    end

    it works.

    but if i want to order by more than 1 column,

    like this

    case

    when x then col1,col2

    when y then col1

    end

    this doesn't work. can anyone help me.

    Thanks

  • You can do it like this:

    order by

    case when x = 1 then col1

    when y = 1 then col1

    end,

    case when x = 1 then cols

    end

    Robert W. Marda

    SQL Programmer

    bigdough.com

    The world’s leading capital markets contact database and software platform.

    Robert W. Marda
    Billing and OSS Specialist - SQL Programmer
    MCL Systems

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

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