首页 > 其他 > 详细

分页存储过程

时间:2020-06-06 11:05:22      阅读:45      评论:0      收藏:0      [点我收藏+]
create proc FY_GetCityList 
(
    @page int,
    @rows int,
    @rowCount int out
)
as 
begin
--定义字符串变量,表示之后执行的sql语句
declare @strSql nvarchar(2000)
set @strSql=Nselect top(+STR(@rows)+) * from (select ROW_NUMBER() over(order by id) as rowNum,* from city )as a where rowNum>+STR((@page-1)*@rows)

print @strSql --打印输出拼接后的sqlyuj
--执行sql语句
exec(@strSql)
--获取总记录数
set @strSql = select @total=count(0) from city
print @strSql

exec sp_executesql @strSql,N@total int out,@total=@rowCount out

end

--执行存储过程
declare @count int
exec FY_GetCityList 1,3,@count out
print @count

 

分页存储过程

原文:https://www.cnblogs.com/lina0621/p/13053546.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!