日期:2014-05-18 浏览次数:20496 次
set @sql='with table_temp as (select row_number() over(order by '+@columnName+') as rowIndex,* from '+@tableName+') select * from table_temp where rowIndex between '+@startIndex+' and '+@endIndex +@where1 +@orderBydesc --select @sql exec(@sql)
------解决方案--------------------
去看看2000通用的分页吧!一般是要加主键ID,然后用TOP来分页处理的。
------解决方案--------------------
分页的存过--来自CSDN CREATE PROCEDURE [dbo].[Basic_Pagination2005] @tblName nvarchar(200), --表名 @fidlelist nvarchar(1000), --要查询字段 @fldName nvarchar(100), --排序字段 @PageSize int, --页尺寸 @PageIndex int, --页码 @IsReCount bit , -- 返回记录总数, 非 0 值则返回 @OrderType bit, -- 设置排序类型, 非 0 值则降序 @strWhere nvarchar(1000) --查询条件 AS declare @sqlstr nvarchar(4000), @tmpwhere nvarchar(4000),@tmporder nvarchar(100) BEGIN if @OrderType != 0 begin set @tmporder = @fldName +' desc ' end else begin set @tmporder = @fldName +' asc ' end set @tmpwhere=''; if(@strWhere!='') begin set @tmpwhere=' where '+@strWhere; end set @sqlstr=N'select * from (select '+@fidlelist+', ROW_NUMBER() OVER(order by '+@tmporder+') as row from '+@tblName+@tmpwhere+') tmp where row between '+cast (((@PageIndex-1)*@PageSize+1) as nvarchar)+' and '+cast (@PageIndex*@PageSize as nvarchar); exec sp_executesql @sqlstr if @IsReCount != 0 begin set @sqlstr=N'select count(*) as Total from '+ @tblName+@tmpwhere exec sp_executesql @sqlstr end END --返回第三页 EXECUTE [Basic_Pagination2005] 'SC','S#','GRADE',10,3,200,1,'GRADE IS NOT NULL' --返回第10页 EXECUTE [Basic_Pagination2005] 'SC','S#','GRADE',10,10,200,1,'GRADE IS NOT NULL' DROP PROC [Basic_Pagination2005]
------解决方案--------------------
--分页存过2 CREATE PROC spMyp @tbname sysname, --要分页显示的表名 @FieldKey nvarchar(1000), --用于定位记录的主键(惟一键)字段,可以是逗号分隔的多个字段 @PageCurrent int=1, --要显示的页码 @PageSize int=10, --每页的大小(记录数) @FieldShow nvarchar(1000)='', --以逗号分隔的要显示的字段列表,如果不指定,则显示所有字段 @FieldOrder nvarchar(1000)='', --以逗号分隔的排序字段列表,可以指定在字段后面指定DESC/ASC @Where nvarcha