复制create procedure SP_PHP_PAGE @qry varchar(16384),分页@iStart int, @iLimit int, @sKeyFiled varchar(32) as /*@qry SQL语句, @iStart 开始, @iLimit 结束,@sKeyFiled 表中的主键 */ begin declare @execsql varchar(16384) declare @execsqltmp varchar(16384) /*定义临时表表名*/ declare @dt varchar(10) --生成临时表的服务器租用随机数 set @dt=substring(convert(varchar, rand()), 3, 10) --一个字符型的亿华云随机数 set rowcount @iLimit if(@sKeyFiled is null) begin set @execsql = stuff(@qry,charindex(select,@qry),6,select number(*) as sybid,) set @execsqltmp = select * from #temptable + @dt + where sybid> || convert(varchar,@iStart) || and sybid <= || convert(varchar,(@iStart/@iLimit+1)*@iLimit) end else begin set @execsql = stuff(@qry,charindex(select,@qry),6,select number(*) as sybid, || @sKeyFiled || ,@ ) set @execsql = stuff(@execsql,charindex(,@,@execsql),charindex(from,@execsql)-charindex(,@,@execsql), ) set @execsqltmp = select || @sKeyFiled || from #temptable + @dt + where sybid> || convert(varchar,@iStart) || and sybid <= || convert(varchar,(@iStart/@iLimit+1)*@iLimit) set @execsqltmp = stuff(@qry,charindex(where,@qry),5, where || @sKeyFiled || in (|| @execsqltmp ||) and ) end set @execsql = stuff(@execsql, charindex(from,@execsql),4,into #temptable + @dt + from) select (@execsql) as sql, @execsqltmp as sqlTmp set rowcount 0 end 1.2.3.4.5.6.7.8.9.10.11.12.13.14.15.16.17.18.19.20.21.22.23.24.25.26.27.28.网站模板