分页存储过程.

ALTER  procedure [dbo].[CMS_GetRecord]  @PageIndex int = 1,  @PageSize int = 15,  @Where varchar(400) = '',  @OrderBy varchar(50) = 'record_id',  @OutPut int output as Begin  Declare @strSql varchar(500)
 DECLARE   @SQL   NVARCHAR(1000)  DECLARE   @R BIGINT
 SET   @SQL=  N'select @R=count(*) from  cms_record LEFT JOIN cms_record_content ON record_id=content_record_id AND content_lang_id=1 WHERE 1=1 '+@Where  EXEC  SP_EXECUTESQL   @SQL,  N' @R BIGINT OUTPUT',  @R OUTPUT  SET   @OutPut=  @R --set @OutPut = @@RowCount  if(@PageIndex =1)  Begin     set @strSql='select top '+str(@PageSize)+' record_id,record_order_num,record_section_id,record_display,record_display_from,record_display_to,record_pdf_filename,record_picture_filename,record_word_filename,record_related_links_category,record_url,record_sample_type,record_sample_category,record_status,content_title,content_detail from cms_record LEFT JOIN cms_record_content ON record_id=content_record_id AND content_lang_id=1 WHERE 1=1 '+@Where+' order by '+@OrderBy+' ASC'  End  Else  Begin     set @strSql='select top '+str(@PageSize)+' record_id,record_order_num,record_section_id,record_display,record_display_from,record_display_to,record_pdf_filename,record_picture_filename,record_word_filename,record_related_links_category,record_url,record_sample_type,record_sample_category,record_status,content_title,content_detail from cms_record LEFT JOIN cms_record_content ON record_id=content_record_id AND content_lang_id=1 where ( '+@OrderBy      +' < ( select Min( '+@OrderBy+') from ( select top '+str(@PageSize*(@PageIndex-1))+' * from  cms_record LEFT JOIN cms_record_content ON record_id=content_record_id AND content_lang_id=1 order by '      +@OrderBy+' ASC) as tempTable)) order by '+ @OrderBy+' ASC'  End
 exec(@strSql) End
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值