Click here to Skip to main content
15,891,707 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more: , +
SQL
WITH MEM AS
(
    SELECT ROW_NUMBER() OVER ( ORDER BY PRODUCTID) AS ROWNUMBER,PRODUCTNAME FROM PRODUCTS
)

SELECT * FROM MEM ORDER BY ROWNUMBER DESC



I want to make a stored procedure. This block is a part of that procedure. Can any one please tell me how can I make this select query dynamic? Query I will pass from asp.net.

Thanks in advance.
Posted
Updated 30-Aug-10 6:42am
v4

I guess you actually need to know how to write a Stored Procedure for Pagination in SQL Server 2005 using Dynamic SQL (Dynamic SQL is required because you would need to pass Page number, Page size, Order By field and Order Direction (Desc or Asc)

If that is so, you can have a look at This Article[^] to learn how to write pagination queries using Dynamic SQL in SQL Server.
 
Share this answer
 
v2
Comments
hiren soni 30-Aug-10 13:46pm    
NO dear I already know how to write a stored procedure, whatever parameters u told me I have already written a stored procedure using those parameters. But in my application there are more than 10 pages where I need paging. I dont want to write 10 stored procedure for that. So I am trying to take a query as a parameter. So with one stored procedure only I can Pass multiple query and use it in N times.
Al-Farooque Shubho 30-Aug-10 14:33pm    
The link I have provided has a "Generic stored procedure" that you can use to get paginated data for any table from SQL Server. I didn't try it but hopefully this is something you need. Best of luck.
You please take a look at this article : http://www.15seconds.com/issue/070628.htm[^]. This has a "Generic" stored procedure that you can use to get paginated data for any table from SQL Server.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900