Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 Order by on stored procedure

Author  Topic 

marcuscoker
Starting Member

13 Posts

Posted - 2007-03-01 : 09:37:47
Hi

I was wondering if anybody could help me with this. I have a stored procedure that returns a recordset to an asp page. I pass values @paremeter.... to filter the stored procedure by a querystring. Now what i would like to do is have a dynamic order by on the stored procedure, where the user is able to click a hyperlink which passes a query string with an order by command that will filtere the recordset that is returned by the stored procedure. Can anybody advise?

Thanks

Marcus

snSQL
Master Smack Fu Yak Hacker

1837 Posts

Posted - 2007-03-01 : 10:19:42
If you only have a few possible sort orders, you can just put the same query with different ORDER BY clauses into an IF ... ELSE block in the stored procedure. If you have a large number then you could use dynamic SQL, you do that with the EXEC statement or sp_executesql stored procedure.

You will find IF ... ELSE, EXEC, and sp_executesql documented with examples in Books Online. Once you try them, if you have any problems then post your code here and someone can help you get it right.
Go to Top of Page

marcuscoker
Starting Member

13 Posts

Posted - 2007-03-01 : 10:39:08
thanks
Go to Top of Page
   

- Advertisement -