create proc Pager
@PageIndex int,
@PageSize int,
@PageCount int out,
@RecordCount int out
as
select @RecordCount= count(*) from film_type
set @PageCount = CEILING(@RecordCount * 1.0 / @PageSize)
declare @topCount int
SET @topCount = @RecordCount - @PageSize * @PageIndex
DECLARE @SQLSTR NVARCHAR(1000)
if @PageIndex=0 or @RecordCount <=0
begin
    set @SQLSTR=N'select top '+str(@PageSize) +' film_id,film_name from film_type order by film_id desc'
end
else
begin
   if @PageIndex=@PageCount-1
   begin
      set @SQLSTR=N'select * from (select top '+str(@topCount)+' film_id,film_name from film_type order by film_id asc)T order by film_id desc'
   end
   else
   begin
     set @SQLSTR=N'select top '+str(@PageSize)+' * from (select top '+str(@topCount)+' film_id,film_name from film_type order by film_id asc)T order by film_id desc '
   end
end
print @SQLSTR
EXEC (@SQLSTR)

drop proc Pager

declare @pageCount int
declare @recordCount int
exec Pager 0,5,@pageCount out,@recordCount out

本文使用Blog_Backup未注册版本导出,请到soft.pt42.com注册。

相关文章:

  • 2021-08-21
  • 2022-03-08
  • 2022-01-25
  • 2021-12-02
  • 2021-08-24
  • 2022-12-23
猜你喜欢
  • 2021-09-15
  • 2021-12-14
  • 2022-03-09
  • 2022-12-23
  • 2021-09-03
相关资源
相似解决方案