存储过程在服务器上已经创建成功了~
存储过程如下:
CREATE procedure [dbo].[SP_Paging_My]
(
@tblName VarChar(2000),
@pagesize int,
@pageindex int,
@docount bit,
@key VarChar(50),
@order VarChar(100)
)
as
declare @strSQL varchar(5000) -- ???
set nocount on
if(@docount!=0)
set @strSQL = 'select count(' + @key + ') from ' + @tblName
else
begin
declare @PageLowerBound int
declare @PageUpperBound int
set @PageLowerBound=(@pageindex-1)*@pagesize
set @PageUpperBound=@PageLowerBound+@pagesize
create table #pageindex(id int identity(1,1) not null,nid int)
set rowcount @PageUpperBound
set @strSQL = 'insert into #pageindex(nid) select ' + @key + ' from '+ @tblName + ' order by ' + @order
exec (@strSQL)
set @strSQL = 'select tmp.* from ' + @tblName +',#pageindex p where tmp.' + @key + '=p.nid and p.id>' + str(@PageLowerBound) +' and p.id<=' + str(@PageUpperBound)
end
--将选出的结果放到临时表中
--exec ('insert into test(result) values ('''+ @strSQL + ''')')
exec (@strSQL)
set nocount off