• Sean Lange (10/2/2012)


    You should read this article from Gail about catch all queries. http://sqlinthewild.co.za/index.php/2009/03/19/catch-all-queries/[/url]

    Thanks, I've read it and it answers my question...

    But is there a way of having a dynamic ORDER BY with CASE clause without having N order columns?!

    ORDER BY CASE WHEN @ordfld = 1 THEN MoneyField WHEN @ordfld = 2 THEN NameField END

    this raises an error.. it has to be written

    ORDER BY CASE WHEN @ordfld = 1 THEN MoneyField END, CASE WHEN @ordfld = 2 THEN NameField END

    which makes 3 order by clauses when I only want one, even if they can be NULL...

    Thanks,

    Pedro



    If you need to work better, try working less...