手机版
你好,游客 登录 注册 搜索
背景:
阅读新闻

SQL Server分页存储过程

[日期:2012-09-04] 来源:Linux社区  作者:jinbiao520 [字体:大 中 小]

SQL Server分页存储过程

create procedre up_GetDataByPage

(

   @pageSize int                     --每页显示记录数

   @curPage int                       --当前页

   @condition varchar(max)    --筛选条件

   @count int output                --输出参数,总记录数

)

--获取总记录数

declare @temp_sql varchar(max)

set @temp_sql='select @temp=count(*) from dt_name where '+@condition

exec sp_executesql @temp_sql,N'@temp int output',@count output

declare @begin int,@end int

set @begin=(@curPage-1)*@pageSize+1

set @end=@curPage*@pageSize

declare @sql varchar(max)

set @sql='select * from (select *,ROW_NUMBER() OVER(order by id desc) as num from dt_name where '+@condition+' ) a where a.num between  '+CONVERT(varchar(10),@begin)+' and '+CONVERT(varchar(10),@end)

exec(@sql)

注意:字符串拼接时,必须将数值类型转换成字符串类型

linux
相关资讯       SQL Server 
本文评论   查看全部评论 (0)
表情: 表情 姓名: 字数

       

评论声明
  • 尊重网上道德,遵守中华人民共和国的各项有关法律法规
  • 承担一切因您的行为而直接或间接导致的民事或刑事法律责任
  • 本站管理人员有权保留或删除其管辖留言中的任意内容
  • 本站有权在网站内转载或引用您的评论
  • 参与本评论即表明您已经阅读并接受上述条款