Home Forums SQL Server 7,2000 T-SQL Setting dynamic Order By in Stored Procedure RE: Setting dynamic Order By in Stored Procedure

  • Hey Mike,

    Make it simple, as the other person said, use constructed queries, thats basically, u will have to arrange the SQL statement with a string variable,let say @STR, the have a string variable for SELECT in @str1, then FROM in @str2 and WHERE in @str3 and ORDER BY in @str4, So what u do for the ORDER BY is put a CASE statement and store all the combinations as a string against some values which u will be getting from the input parameter. Then concatenate these string variables in @STR and exec (@str). If you did not understand get back I shall shoot out a sample code. I have done it and it works great.