Expired date sort

  • I need to sort all records with an expired date at the bottom.

    i.e if table_column_ExpDate<getdate() ... (set variable?)

    order by variable, something else, somthing else.

    What's the best way to do this sort of thing?

    Thanks

  • Do you mean something like this:

    SELECT...

    FROM...

    WHERE...

    ORDER BY CASE WHEN @MyVariable = 52 THEN Column1

    WHEN @MyVariable = 42 THEN Column2

    ELSE Column3

    END

    "The credit belongs to the man who is actually in the arena, whose face is marred by dust and sweat and blood"
    - Theodore Roosevelt

    Author of:
    SQL Server Execution Plans
    SQL Server Query Performance Tuning

  • I think this is more of what I was looking for, but thanks.

    ORDER BY case when datediff(day,p.Prodclosedate,getdate()) > 0 then 1 ELSE 2 end

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

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