求一个完整的存储过程分页源码示例?
求一个完整的存储过程分页源码示例? 希望各位大侠帮忙..... (sql分页存储过程及web页面 程序调用(cs)) 在这里谢谢各位了! --------------------编程问答-------------------- http://topic.csdn.net/u/20080402/12/93447beb-f12b-4cb1-bfe7-1468cdfd327b.html这里面有。我回复的。rp dl gridview分页代码和存储 --------------------编程问答-------------------- 我写的一个帖过来的 大部分不用关心 只看对结果分页就行
ALTER PROCEDURE PRO_QUERY_SELECT_CARD_LIST --资产明细查询 zyl 2008-2-3
@fstrKJQJ varchar(50)=null, --会计区间
@fstrdwName varchar(50)=null, --当前单位编码
@assetTypeCode varchar(50)=null, --资产类别编码
@currPageIndex int=0, --当前页索引
@perPageCount int=20, --每页显示记录数
@itemCount int=0 output, --总记录数
@pageCount int=0 output --总页数
--说明:应在讨论后确定净值、评估值的区别后再决定输出净值还是评估值,并加入会计区间限制
AS
SET NOCOUNT ON
DECLARE @minCode varchar(50),@maxCode varchar(50)
SELECT @minCode=minCode,@maxCode=maxCode FROM ASSET_NUM WHERE @assetTypeCode>minCode AND @assetTypeCode<=maxCode
SET @minCode=CASE WHEN @minCode IS NULL OR @minCode='' THEN 'FF' ELSE @minCode END
SET @maxCode=CASE WHEN @maxCode IS NULL OR @maxCode='' THEN 'FF' ELSE @maxCode END
IF EXISTS (SELECT 1 FROM DBO.SYSOBJECTS WHERE ID=OBJECT_ID(N'[DBO].[TEMP_LIST]') AND OBJECTPROPERTY(ID,N'IsUserTable')=1)
BEGIN
DROP TABLE [DBO].[TEMP_LIST]
END
CREATE TABLE [TEMP_LIST]
(
ID INT IDENTITY(1,1),
CARD_ID INT,
DEPT_CODE VARCHAR(50),
DEPT_NAME VARCHAR(50),
ASSET_CODE VARCHAR(50),
ASSET_NAME VARCHAR(50),
USING_STATE VARCHAR(50),
UNIT VARCHAR(50),
FORE_MOUNT DECIMAL(18,2) DEFAULT(0),
FORE_ORIGIN_VALUE DECIMAL(18,2) DEFAULT(0),
FORE_NET_VALUE DECIMAL(18,2) DEFAULT(0),
INC_MOUNT DECIMAL(18,2) DEFAULT(0),
INC_ORIGIN_VALUE DECIMAL(18,2) DEFAULT(0),
INC_NET_VALUE DECIMAL(18,2) DEFAULT(0),
DEC_MOUNT DECIMAL(18,2) DEFAULT(0),
DEC_ORIGIN_VALUE DECIMAL(18,2) DEFAULT(0),
DEC_NET_VALUE DECIMAL(18,2) DEFAULT(0),
FINAL_MOUNT DECIMAL(18,2) DEFAULT(0),
FINAL_ORIGIN_VALUE DECIMAL(18,2) DEFAULT(0),
FINAL_NET_VALUE DECIMAL(18,2) DEFAULT(0)
)
--初始化条件
DECLARE @SQL NVARCHAR(4000),@C NVARCHAR(4000),@TEMPSQL NVARCHAR(4000),@PREFIX NVARCHAR(2000),@SUFFIX NVARCHAR(2000)
SET @PREFIX='SET @itemCount=@itemCount;SET @perPageCount=@perPageCount;SET @currPageIndex=@currPageIndex;'
SET @PREFIX=@PREFIX+'SET @fstrKJQJ=@fstrKJQJ ;SET @fstrdwName=@fstrdwName;SET @maxCode=@maxCode;SET @minCode=@minCode;'+char(13)+char(10)
SET @TEMPSQL='SELECT @itemCount=COUNT(*) FROM CARDS WHERE fintIsVal=1 '
SET @C=' AND (EXISTS(SELECT 1 FROM CARD_MODIFY CM WHERE CM.FSTRASSETNAME=CARDS.FSTRASSETNAME AND CM.FSTRTYPE NOT IN(''注销'')) OR NOT EXISTS(SELECT 1 FROM CARD_MODIFY WHERE CARD_MODIFY.FSTRASSETNAME=CARDS.FSTRASSETNAME)) '
SET @C=@C+(CASE WHEN @fstrKJQJ IS NOT NULL AND @fstrKJQJ<>'' THEN ' AND fstrKJQJ=@fstrKJQJ ' ELSE '' END)
SET @C=@C+(CASE WHEN @fstrdwName IS NOT NULL AND @fstrdwName<>'' THEN ' AND fstrdwName =@fstrdwName ' ELSE '' END)
SET @C=@C+(CASE WHEN @assetTypeCode IS NOT NULL AND @assetTypeCode<>'' THEN ' AND (LEFT(fstrAssetName,2)>@minCode AND LEFT(fstrAssetName,2)<=@maxCode) ' ELSE '' END)
SET @TEMPSQL=@PREFIX+@TEMPSQL+@C
print @tempsql
exec sp_executesql @TEMPSQL,
N'
@fstrKJQJ varchar(50)=null,
@fstrdwName varchar(50)=null,
@minCode varchar(50)=null,
@maxCode varchar(50)=null,
@itemCount int=0 output,
@perPageCount int=0,
@currPageIndex int=0',
@fstrKJQJ=@fstrKJQJ,
@fstrdwName=@fstrdwName,
@minCode=@minCode,
@maxCode=@maxCode,
@itemCount=@itemCount output,
@perPageCount=@perPageCount,
@currPageIndex=@currPageIndex
--在临时表中填写资产基本信息
SET @perPageCount=CASE WHEN @perPageCount IS NULL OR @perPageCount<=0 THEN 20 WHEN @perPageCount>@itemCount AND @itemCount<>0 THEN @itemCount ELSE @perPageCount END
DECLARE @LEFT INT --尾页项数
SET @pageCount=CASE WHEN @itemCount=0 THEN 0 WHEN @itemCount=@perPageCount THEN 1 ELSE @itemCount/@perPageCount+1 END
SET @currPageIndex=CASE WHEN @currPageIndex IS NULL OR @currPageIndex<0 OR @pageCount=1 THEN 0 WHEN @currPageIndex>(@pageCount-1) THEN @pageCount-1 ELSE @currPageIndex END
print @itemcount
print @perpagecount
SET @LEFT=CASE WHEN @itemCount%@perPageCount=0 THEN @perPageCount ELSE @LEFT END
IF (@currPageIndex+1)*@perPageCount<=@itemCount
BEGIN
SET @SQL=@PREFIX+'INSERT INTO TEMP_LIST(CARD_ID,ASSET_CODE,ASSET_NAME,DEPT_CODE,DEPT_NAME,USING_STATE,UNIT)
SELECT AUTO_ID,fstrAssetName,fstrAssetDesc,fstrDwName,fstrDwDesc,fstrUsed,''单位'' FROM (SELECT TOP '+STR(@perPageCount)+' * FROM (SELECT TOP '+STR(@perPageCount*(@currPageIndex+1))+' CARDS.*,(SELECT FSTRDWDESC FROM ZC_DWXX WHERE ZC_DWXX.FSTRDWNAME=CARDS.FSTRDWNAME) AS fstrDwDesc FROM CARDS WHERE fintIsVal=1 '
END
ELSE
BEGIN
SET @SQL=@PREFIX+'INSERT INTO TEMP_LIST(CARD_ID,ASSET_CODE,ASSET_NAME,DEPT_CODE,DEPT_NAME,USING_STATE,UNIT)
SELECT AUTO_ID,fstrAssetName,fstrAssetDesc,fstrDwName,fstrDwDesc,fstrUsed,''单位'' FROM (SELECT TOP '+STR(@LEFT)+' * FROM (SELECT TOP '+STR(@itemCount)+' CARDS.*,(SELECT FSTRDWDESC FROM ZC_DWXX WHERE ZC_DWXX.FSTRDWNAME=CARDS.FSTRDWNAME) AS fstrDwDesc FROM CARDS WHERE fintIsVal=1 '
END
SET @SUFFIX=' ORDER BY CARDS.AUTO_ID DESC) AS T1 ORDER BY T1.AUTO_ID ASC) AS T2 ORDER BY T2.AUTO_ID DESC; '+CHAR(13)+CHAR(10)
SET @SQL=@SQL+@C+@SUFFIX
-- PRINT STR(LEN(@SQL))+':'+@SQL
--/*
exec sp_executesql @SQL,
N'
@fstrKJQJ varchar(50)=null,
@fstrdwName varchar(50)=null,
@minCode varchar(50)=null,
@maxCode varchar(50)=null,
@itemCount int=0 output,
@perPageCount int=0,
@currPageIndex int=0',
@fstrKJQJ=@fstrKJQJ,
@fstrdwName=@fstrdwName,
@minCode=@minCode,
@maxCode=@maxCode,
@itemCount=@itemCount output,
@perPageCount=@perPageCount,
@currPageIndex=@currPageIndex
--*/
--填充数值信息
DECLARE @assetCode VARCHAR(50),@offset VARCHAR(20)
declare @i int
DECLARE @bgMount decimal(18,2),@bgOriValue decimal(18,2),@bgNetValue decimal(18,2)
DECLARE @incMount decimal(18,2),@incOriValue decimal(18,2),@incNetValue decimal(18,2)
DECLARE @decMount decimal(18,2),@decOriValue decimal(18,2),@decNetValue decimal(18,2)
DECLARE @endMount decimal(18,2),@endOriValue decimal(18,2),@endNetValue decimal(18,2)
SET @bgMount=0 SET @bgOriValue=0 SET @bgNetValue=0
SET @incMount=0 SET @incOriValue=0 SET @incNetValue=0
SET @decMount=0 SET @decOriValue=0 SET @decNetValue=0
SET @endMount=0 SET @endOriValue=0 SET @endNetValue=0
SET @offset=dbo.FuncGetBeginAccountOffsetStr(dateadd(year,-1,getdate())) --取当前年份的开始会计区间 这里是为测试用 取了去年的数据
DECLARE CUR CURSOR FOR SELECT card_id,ASSET_CODE FROM TEMP_LIST
OPEN CUR
FETCH NEXT FROM CUR INTO @i,@assetCode
WHILE(@@FETCH_STATUS=0)
BEGIN
--如果没有变动记录
IF NOT EXISTS(SELECT 1 FROM CARD_MODIFY WHERE FSTRASSETNAME=@assetCode)
BEGIN
SELECT @bgMount=CASE WHEN FdblUserDesign2 IS NULL THEN 0 ELSE FdblUserDesign2 END,
@bgOriValue=CASE WHEN fcurAmount1 IS NULL THEN 0 ELSE fcurAmount1 END,
@bgNetValue=CASE WHEN fcurAmount IS NULL THEN 0 ELSE fcurAmount END
FROM CARDS WHERE FSTRASSETNAME=@assetCode
SET @endMount=@bgMount SET @endOriValue=@bgOriValue SET @endNetValue=@bgOriValue
END
ELSE
BEGIN
--从变动表统计数据
SELECT TOP 1 @bgMount=CASE WHEN Fdbloldcount IS NULL THEN 0 ELSE Fdbloldcount END,
@bgOriValue=CASE WHEN Fcuroldamount1 IS NULL THEN 0 ELSE Fcuroldamount1 END,
@bgNetValue=CASE WHEN fcuroldamount IS NULL THEN 0 ELSE fcuroldamount END
FROM CARD_MODIFY WHERE FSTRASSETNAME=@assetCode ORDER BY AUTO_ID ASC
DECLARE @type varchar(50)
SELECT @type=FSTRTYPE FROM CARD_MODIFY WHERE FSTRASSETNAME=@assetCode
END
FETCH NEXT FROM CUR INTO @i,@assetCode
END
CLOSE CUR
DEALLOCATE CUR
SELECT * FROM TEMP_LIST
RETURN
调用(如QCardListInfo等是自定义类):
QCardListInfo q = new QCardListInfo();
q.AssetTypeCode = assetTypeCode;
q.PerPageCount = 19;
DataTable dt= Query.CardList(ref q);
GridView1.DataSource=dt.Defaultview;
GridView1.DataBind();
大概是这样了
--------------------编程问答--------------------
CREATE PROCEDURE dbo.aspnet_Membership_GetAllUsers
@ApplicationName nvarchar(256),
@PageIndex int,
@PageSize int
AS
BEGIN
DECLARE @ApplicationId uniqueidentifier
SELECT @ApplicationId = NULL
SELECT @ApplicationId = ApplicationId FROM dbo.aspnet_Applications WHERE LOWER(@ApplicationName) = LoweredApplicationName
IF (@ApplicationId IS NULL)
RETURN 0
-- Set the page bounds
DECLARE @PageLowerBound int
DECLARE @PageUpperBound int
DECLARE @TotalRecords int
SET @PageLowerBound = @PageSize * @PageIndex
SET @PageUpperBound = @PageSize - 1 + @PageLowerBound
-- Create a temp table TO store the select results
CREATE TABLE #PageIndexForUsers
(
IndexId int IDENTITY (0, 1) NOT NULL,
UserId uniqueidentifier
)
-- Insert into our temp table
INSERT INTO #PageIndexForUsers (UserId)
SELECT u.UserId
FROM dbo.aspnet_Membership m, dbo.aspnet_Users u
WHERE u.ApplicationId = @ApplicationId AND u.UserId = m.UserId
ORDER BY u.UserName
SELECT @TotalRecords = @@ROWCOUNT
SELECT u.UserName, m.Email, m.PasswordQuestion, m.Comment, m.IsApproved,
m.CreateDate,
m.LastLoginDate,
u.LastActivityDate,
m.LastPasswordChangedDate,
u.UserId, m.IsLockedOut,
m.LastLockoutDate
FROM dbo.aspnet_Membership m, dbo.aspnet_Users u, #PageIndexForUsers p
WHERE u.UserId = p.UserId AND u.UserId = m.UserId AND
p.IndexId >= @PageLowerBound AND p.IndexId <= @PageUpperBound
ORDER BY u.UserName
RETURN @TotalRecords
END
cs中我是通过获取DataTable(调用字段显示内容),返回值(控制有多少页) --------------------编程问答--------------------
--------------------编程问答-------------------- 都是存储过程啊,我给个函数
create Proc [dbo].[GetRS]
@QueryStr nvarchar(300),--表名、视图名、查询语句
@PageSize int=10,--每页的大小(行数)
@PageCurrent int=1,--要显示的页
@FdShow nvarchar (100)='',--要显示的字段列表,如果查询结果有标识字段,需要指定此值,且不包含标识字段
@FdOrder nvarchar (100)='',--排序字段列表
@WhereStr nvarchar (200)='', --内容是' id=3 and model_no like '%24%' and '
@RSCount int=0 output
as
set @FdShow=' '+@FdShow+' '
set @FdOrder= ' '+@FdOrder+' '
set @WhereStr= ' '+@WhereStr+' '
declare @FdName nvarchar(250)--表中的主键或表、临时表中的标识列名
,@Id1 varchar(20),@Id2 varchar(20)--开始和结束的记录号
,@Obj_ID int --对象ID
,@Temp nvarchar(300) --临时语句
,@strParam nvarchar(100) --临时参数
declare @strfd nvarchar(2000)--复合主键列表
,@strjoin nvarchar(4000)--连接字段
,@strwhere nvarchar(2000)--查询条件
--检查输入参数
set @QueryStr=ltrim(rtrim(@QueryStr))
select @Obj_ID=object_id(@QueryStr)
,@FdShow=case isnull(@FdShow,'') when '' then ' *' else ' '+@FdShow end
,@FdOrder=case isnull(@FdOrder,'') when '' then '' else ' order by '+@FdOrder end
,@QueryStr=case when @Obj_ID is not null then ' '+@QueryStr else ' ('+@QueryStr+') a' end
--输出总记录数
SET @Temp= 'select @RSCount=count(*) FROM ' + @QueryStr+' '+@WhereStr
SET @strParam = N'@RSCount INT OUT'
EXECUTE sp_executeSQL @Temp,@strParam,@RSCount out
--如果显示第一页,可以直接用top来完成
if @PageCurrent=1
begin
select @Id1=cast(@PageSize as varchar(20))
exec('select top '+@Id1+@FdShow+' from '+@QueryStr+@WhereStr+@FdOrder)
return
end
--如果是表,则检查表中是否有标识更或主键
if @Obj_ID is not null and objectproperty(@Obj_ID,'IsTable')=1
begin
select @Id1=cast(@PageSize as varchar(20))
,@Id2=cast((@PageCurrent-1)*@PageSize as varchar(20))
select @FdName=name from syscolumns where id=@Obj_ID and status=0x80
if @@rowcount=0--如果表中无标识列,则检查表中是否有主键
begin
if not exists(select 1 from sysobjects where parent_obj=@Obj_ID and xtype='PK')
goto lbusetemp--如果表中无主键,则用临时表处理
select @FdName=name from syscolumns where id=@Obj_ID and colid in(
select colid from sysindexkeys where @Obj_ID=id and indid in(
select indid from sysindexes where @Obj_ID=id and name in(
select name from sysobjects where xtype='PK' and parent_obj=@Obj_ID
)))
if @@rowcount>1--检查表中的主键是否为复合主键
begin
select @strfd='',@strjoin='',@strwhere=''
select @strfd=@strfd+',['+name+']'
,@strjoin=@strjoin+' and a.['+name+']=b.['+name+']'
,@strwhere=@strwhere+' and b.['+name+'] is null'
from syscolumns where id=@Obj_ID and colid in(
select colid from sysindexkeys where @Obj_ID=id and indid in(
select indid from sysindexes where @Obj_ID=id and name in(
select name from sysobjects where xtype='PK' and parent_obj=@Obj_ID
)))
select @strfd=substring(@strfd,2,2000)
,@strjoin=substring(@strjoin,5,4000)
,@strwhere=substring(@strwhere,5,4000)
goto lbusepk
end
end
end
else
goto lbusetemp
/*--使用标识列或主键为单一字段的处理方法--*/
lbuseidentity:
if len(@WhereStr)>10
begin
exec('select top '+@Id1+@FdShow+' from '+@QueryStr
+@WhereStr+' and '+@FdName+' not in(select top '
+@Id2+' '+@FdName+' from '+@QueryStr+@WhereStr+@FdOrder
+')'+@FdOrder
)
return
end
else
begin
exec('select top '+@Id1+@FdShow+' from '+@QueryStr
+' where '+@FdName+' not in(select top '
+@Id2+' '+@FdName+' from '+@QueryStr+@FdOrder
+')'+@FdOrder
)
return
end
/*--表中有复合主键的处理方法--*/
lbusepk:
exec('select '+@FdShow+' from(select top '+@Id1+' a.* from
(select top 100 percent * from '+@QueryStr+@FdOrder+') a
left join (select top '+@Id2+' '+@strfd+'
from '+@QueryStr+@FdOrder+') b on '+@strjoin+'
where '+@strwhere+') a'
)
return
/*--用临时表处理的方法--*/
lbusetemp:
select @FdName='[ID_'+cast(newid() as varchar(40))+']'
,@Id1=cast(@PageSize*(@PageCurrent-1) as varchar(20))
,@Id2=cast(@PageSize*@PageCurrent-1 as varchar(20))
exec('select '+@FdName+'=identity(int,0,1),'+@FdShow+'
into #tb from'+@QueryStr+@FdOrder+'
select '+@FdShow+' from #tb where '+@FdName+' between '
+@Id1+' and '+@Id2
)
--------------------编程问答-------------------- ALTER PROCEDURE dbo.StoredProcedure6
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
Create function fu_pagination(
@tblName varchar(255), -- 表名
@strGetFields varchar(1000) = '*', -- 需要返回的列
@fldName varchar(255)='', -- 排序的字段名
@PageSize int = 10, -- 页尺寸
@PageIndex int = 1, -- 页码
@doCount bit = 0, -- 返回记录总数, 非 0 值则返回
@OrderType bit = 0, -- 设置排序类型, 非 0 值则降序
@strWhere varchar(1500) = '' -- 查询条件 (注意: 不要加 where)
)
returns varchar(8000)
AS
begin
declare @strSQL varchar(5000) -- 主语句
declare @strTmp varchar(110) -- 临时变量
declare @strOrder varchar(400) -- 排序类型
if @doCount != 0
begin
if @strWhere !=''
set @strSQL = 'select count(*) as Total from [' + @tblName + '] where '+@strWhere
else
set @strSQL = 'select count(*) as Total from [' + @tblName + ']'
end --以上代码的意思是如果@doCount传递过来的不是0,就执行总数统计。以下的所有代码都是@doCount为0的情况:
else
begin
if @OrderType != 0
begin
set @strTmp = '<(select min'
set @strOrder = ' order by ' + @fldName +' desc'--如果@OrderType不是0,就执行降序,这句很重要!
end
else
begin
set @strTmp = '>(select max'
set @strOrder = ' order by ' + @fldName +' asc'
end
if @PageIndex = 1
begin
if @strWhere != ''
set @strSQL = 'select top ' + str(@PageSize) +' '+@strGetFields+ ' from [' + @tblName + '] where ' + @strWhere + ' ' + @strOrder
else
set @strSQL = 'select top ' + str(@PageSize) +' '+@strGetFields+ ' from ['+ @tblName + '] '+ @strOrder--如果是第一页就执行以上代码,这样会加快执行速度
end
else
begin--以下代码赋予了@strSQL以真正执行的SQL代码
set @strSQL = 'select top ' + str(@PageSize) +' '+@strGetFields+ ' from ['
+ @tblName + '] where [' + @fldName + ']' + @strTmp + '(['+ @fldName
+ ']) from (select top '
+ str((@PageIndex-1)*@PageSize) + ' ['+ @fldName + '] from ['
+ @tblName + ']' + @strOrder + ') as tblTmp)'+ @strOrder
if @strWhere != ''
set @strSQL = 'select top ' + str(@PageSize) +' '+@strGetFields+ ' from ['
+ @tblName + '] where [' + @fldName + ']' + @strTmp + '(['
+ @fldName + ']) from (select top ' + str((@PageIndex-1)*@PageSize) + ' ['
+ @fldName + '] from [' + @tblName + '] where ' + @strWhere + ' '
+ @strOrder + ') as tblTmp) and ' + @strWhere + ' ' + @strOrder
end
end
return @strSQL
end
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
(
@skip int,
@to int
)
AS
set rowcount @to
SELECT t1.theID
from(select ROW_NUMBER() OVER(ORDER BY t0.theID) as [Row_NUMBER],t0.theID from dbo.Table_2 AS t0) as t1
where t1.[Row_NUMBER]>@skip
set rowcount 0
RETURN
--------------------编程问答-------------------- 在 AspNetPager 控件 公认的 分页控件
他的官方网站支持 数据库存储过程 自动 创建
http://www.webdiyer.com/AspNetPager/utility/sqlspgen.aspx
--------------------编程问答--------------------
create procedure Page
(@Name VarChar,
@pagesize int,
@pageindex int,
@docount bit)
as
set nocount on
if(@docount=1)
select count(*) from WebShop
else
begin
declare @indextable table(id int identity(1,1),nid int)
declare @PageLowerBound int
declare @PageUpperBound int
set @PageLowerBound=(@pageindex-1)*@pagesize
set @PageUpperBound=@PageLowerBound+@pagesize
set rowcount @PageUpperBound
insert into @indextable(nid) select int from WebShop order by Id desc
select * from WebShop O,@indextable t where O.int=t.nid
and t.id between @PageLowerBound+1 and @PageUpperBound order by t.id
end
set nocount off
SET ANSI_NULLS ON--------------------编程问答--------------------
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author: hao.w
-- Create date: 2008.1.15
-- Description: SqlServer2005通用分页方法
-- =============================================
create PROCEDURE sp_CommonPage
(@sql nvarchar(4000), @BeginIndex int, @EndIndex int)
AS
BEGIN
DECLARE @ResultSql nvarchar(4000);
DECLARE @OrderStr nvarchar(400);
DECLARE @SelectStr nvarchar(3000);
DECLARE @OtherStr nvarchar(1000);
DECLARE @ColumnsStr nvarchar(2000);
DECLARE @OrderIndex int;
DECLARE @FromIndex int;
SET @OrderIndex = Charindex('Order',@sql,0);
SET @FromIndex= Charindex('From',@sql,0);
SET @SelectStr = Left(@sql,@FromIndex-1);
SET @ColumnsStr = Substring(@Sql,7,@FromIndex-7);
SET @OtherStr = Substring(@sql, @FromIndex,@OrderIndex-@FromIndex);
SET @ORderStr = Right(@sql,len(@sql)-@OrderIndex+1);
SET @ResultSql = @SelectStr + ',row_number() Over('+@OrderStr+') RowNumber '
+@OtherStr;
Set @ResultSql = 'Select '+@ColumnsStr+' from('+@ResultSql+')Temp where RowNumber between '
+Str(@BeginIndex) + ' AND ' + Str(@EndIndex)
EXEC(@ResultSql)
END
EXEC(@ResultSql)--------------------编程问答--------------------
友情提示:
-----------------------------
俄罗斯
-----------------------------
补充:.NET技术 , ASP.NET