-- Sqlserver 2005 저장 프로시저 페이지
1951 단어 sqlserver2005
http://www.cnblogs.com/xuanye/archive/2009/11/08/Xuanye_jQuery_FlexiGrid_Demo.html
/****** : StoredProcedure [dbo].[PAGESELECT] : 05/19/2010 10:34:11 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author: <wangshaoming>
-- Create date: <2008-12-12>
-- Description: < >
-- =============================================
ALTER PROCEDURE [dbo].[PAGESELECT]
@SQLPARAMS nvarchar(2000)='', --
@PAGESIZE int=20,--
@PAGEINDEX int=0, -- ,
@SQLTABLE varchar(5000),-- , sql
@SQLCOLUMNS varchar(4000),--
@SQLPK varchar(50),--
@SQLORDER varchar(200),--
@Count int=-1 output
AS
BEGIN
SET NOCOUNT ON;
DECLARE @PAGELOWERBOUND INT
DECLARE @PAGEUPPERBOUND INT
DECLARE @SQLSTR nvarchar(4000)
--
IF @PAGEINDEX=0 -- ,
BEGIN
set @SQLSTR=N'select @sCount=count(1) FROM '+@SQLTABLE+' WHERE 1=1'+@SQLPARAMS
Exec sp_executesql @sqlstr,N'@sCount int outPut',@Count output
END
ELSE
BEGIN
SET @COUNT =-1
END
SET @PAGELOWERBOUND= @PAGEINDEX *@PAGESIZE+1
SET @PAGEUPPERBOUND = @PAGELOWERBOUND +@PAGESIZE-1
IF @SQLORDER=''
BEGIN
SET @SQLORDER='ORDER BY '+@SQLPK
END
SET @SQLSTR=N'SELECT * FROM (select '+@SQLCOLUMNS+',ROW_NUMBER() Over('+@SQLORDER+') as PAGESELECT_rowNum FROM '+@SQLTABLE+' WHERE 1=1'+@SQLPARAMS+ ') as PAGESELECT_TABLE
where PAGESELECT_rowNum between '+STR(@PAGELOWERBOUND)+' and '+STR(@PAGEUPPERBOUND)+' '
Exec sp_executesql @SQLSTR
SELECT @COUNT
END