81,092
社区成员
发帖
与我相关
我的任务
分享
USE [Book]
GO
/****** Object: StoredProcedure [dbo].[BooksPage] Script Date: 01/17/2012 08:22:01 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER procedure [dbo].[BooksPage]
@curPage int=1,
@perPageRecords int,
@sqlstr varchar(255),
@countpage int output
as
declare @total_count int
if exists (select 1 from sysobjects where id = object_id('total_count') and type = 'U') drop table total_count
create table total_count(toll int)
execute( 'insert into total_count select count(*) from Books ' + @sqlstr)
select @total_count = toll from total_count
drop table total_count
declare @page_in_show int
set @page_in_show=@total_count-(@curPage-1)*@perPageRecords
set @countpage=(@total_count+@perPageRecords -1)/@perPageRecords
exec('select top '+@perPageRecords+' * from (select top '+@page_in_show+' * from Books '+@sqlstr+' order by Books_ID desc) as a order by Books_ID asc')