USE [AWS2] GO /****** Object: StoredProcedure [dbo].[TestGetinvByPage] Script Date: 07/11/2007 14:27:48 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO ALTER PROC [dbo].[TestGetinvByPage] (@PageSize int = 10 , @PageNumber int = 2, @kw Varchar (40) = 'pencil', @clientid int = 2) AS Declare @RowStart int Declare @RowEnd int if @PageNumber > 0 Begin SET @PageNumber = @PageNumber -1 SET @RowStart = @PageSize * @PageNumber + 1; SET @RowEnd = @RowStart + @PageSize - 1 ; with InvRows as ( select uid,isbn13,description from inv where uidclient = @clientid and contains("description",@kw) union select uid,isbn13,description from inv where uidclient = 0 and contains("description",@kw) ) With InvRecs AS ( SELECT uidclient, uid, description, ROW_NUMBER() OVER (order by uid) as RowNumber FROM Invrows ) select * from Invrecs Where RowNumber >= @RowStart and RowNumber <= @RowEnd END