Declare@PageSizeint set@PageSize=8 Declare@PageIndexint set@PageIndex=1 --定义输出的参数 Declare@RecoundCountint Declare@DateEofBit--output,--返回数据,是否溢出 Declare@PageCountint--output--返回数据:总页数 Declare@TempResultvarchar(1000) Declare@OrderCommandvarchar(1000) Set@TempResult='Select * From dbo.Info_ProductInfo where Display=1 And Audting=0' Declare@GetRCountSumStrnvarchar(1500) Set@GetRCountSumStr='Select @RecoundCount = Count(*) From ('+@TempResult+') as t' Exec sp_executesql @GetRCountSumStr,N'@RecoundCount int output',@RecoundCount output Declare@ResultModint Set@ResultMod=@RecoundCount%@PageSize If@ResultMod=0 Set@PageCount=@RecoundCount/@PageSize Else Set@PageCount= (@RecoundCount/@PageSize) +1 Set@DateEof=0 If@PageIndex<1 Set@PageIndex=1 if@PageIndex>@PageCount Set@PageIndex=@PageCount Declare@GetProductAuditingListvarchar(3000) Declare@indextabletable(id intidentity(1,1),PId int) --'Insert Into @indextable(PId)' + @TempResult Set@GetProductAuditingList=(' Declare @indextable table(id int identity(1,1),SysId int) Insert Into @indextable(SysId) Select SysId From ('+@TempResult+') as t Select P.*,u.UserName,C.CCnName,T.Id From @indextable as T,dbo.Info_UserInfo As u,Info_CompanyInfo as C,dbo.Info_ProductInfo as p Where Id > '+cast((@PageSize*@PageIndex) -@PageSizeasvarchar(10)) +' And Id <= '+cast((@PageSize*@PageIndex) asvarchar(10)) + 'And P.SysId = T.SysId And p.UserId=u.SysId and P.CompanyId=C.SysID Order By T.Id') Exec(@GetProductAuditingList)