Passing Sort Parameter to Stored Procedure

Passing Sort Parameter to Stored Procedure

Post by Drew Burlingam » Sat, 17 Feb 2001 14:51:27

I'm using stored procedures to process commands and then return a result set to
an ASP page.  The result set is 10 columns, and the user needs to be able to sort
by any column.  How do I  pass the field to sort by into the stored procedure so
that it will return the correctly sorted recordset. (or what syntax do I use).  I
looked into sorting the script recordset but didn't see a way to do that.

Any suggestions?



Passing Sort Parameter to Stored Procedure

Post by Mujahid Wazi » Sat, 17 Feb 2001 15:10:30


You can do this using dynamic SQL.

USE pubs
-- Order by the first name

-- Order by the last name



Passing Sort Parameter to Stored Procedure

Post by Drew Burlingam » Sat, 17 Feb 2001 15:20:16

Mujahid, you're my hero.

I'm new to this and thought that there should be a way to do this and sure enough, there is.

Thanks so much.

*** Sent via Developersdex ***
Don't just participate in USENET...get rewarded for it!


1. Passing Parameters down to a buried view or stored procedure using parameters

I am a bit of a newbie and am trying to understand how to simplify a
complex SQL Select statement by using a series of views, but needing to
specifying parameters at one of the deeper levels, so I thought that
given parameters, stored procedures were the way to go, but how can I
treat a stored procedure like a view or vice versa?

Say I have a stored procedure,  proc1, which is defined as

    Select * from table1 where col1 is between the two date parameters

I wish to execute another procedure which has additional parameters and
additional tables which are to join to proc1, passing the parameters
proc1 requires down the line.

Is there some way to achieve this, or do I need to expose the parameters
at the surface level?

Alternatively, is there some way to pass parameters to a view?

2. question on SQLSetStmtAttr on SQL_ATTR_MAX_ROWS attribute

3. Passing multiple parameters for a parameter using temporary stored procedures

4. inserting date

5. Sorting Stored procedure using a parameter

6. dynamic cursor and PL/SQL

7. Stored Procedure: Specifying ASC or DESC sort order through a parameter

8. Q&A Information

9. Specifying sort order as a stored procedure parameter

10. Q:Sorting A Grid Bound To A Ado DataControl Using A Parameter'd Stored Procedure

11. Passing a parameter to a stored procedure

12. Passing a Table Name as a Stored Procedure Parameter

13. How to pass parameter for an order by clause in stored procedure