用存储过程实现分页 给出字段有表,id,pagesize,currpage

来源:百度知道 编辑:UC知道 时间:2024/07/02 01:30:20
这也是一道面试题 要求用sql实现 要详细步骤

直接用就可以了 简单实用。。
--@datasrc
-- the table (or stored procedure, etc.) name
--@orderBy
-- the ORDER BY clause
--@fieldlis
-- the fields to return (including calculated expressions)
--@filter
-- the WHERE clause
--@pageNum
-- the page to return (must be greater than or equal to one)
--@pageSize
-- the number of records per page
CREATE PROCEDURE pager
@datasrc nvarchar(200)
,@orderBy nvarchar(200)
,@fieldlist nvarchar(200) = '*'
,@filter nvarchar(200) = ''
,@pageNum int = 1
,@pageSize int = NULL
AS
SET NOCOUNT ON
DECLARE
@STMT nvarchar(max) -- SQL to execute
,@recct int -- total # of records (for GridView paging interface)
IF LTRIM(RTRIM(@filter)) = '' SET @filter = '1 = 1'
IF @pageSize IS NULL BEGIN
SET @STMT = 'SELECT ' + @fieldlist +
&#