thanks to you i am new to dynamic sql so i found these articles are very usefulthanks againand now it's workingCREATE PROCEDURE [dbo].[GetProducts]( @WhereClause varchar (2000) = Null , @OrderBy varchar (2000) = Null , @PageIndex int , @PageSize int, @ItemCount int output )AS BEGIN DECLARE @PageLowerBound int DECLARE @PageUpperBound int /*DECLARE @paramList nvarchar(1000)*/ DECLARE @RtnCount int -- Set the page bounds SET @PageLowerBound = (@PageIndex - 1) * @PageSize SET @PageUpperBound = @PageLowerBound + @PageSize -- Create a temp table to store the select results Create Table #PageIndex ( [IndexId] int IDENTITY (1, 1) NOT NULL, [ProductID] int ) -- Insert into the temp table declare @SQL as nvarchar(4000) SET @SQL = 'INSERT INTO #PageIndex (ProductID)' SET @SQL = @SQL + ' SELECT' IF @PageSize > 0 BEGIN SET @SQL = @SQL + ' TOP ' + convert(nvarchar, @PageUpperBound) END SET @SQL = @SQL + ' [ProductID]' SET @SQL = @SQL + ' FROM dbo.[Products]' IF LEN(@WhereClause) > 0 BEGIN SET @SQL = @SQL + ' WHERE ' + @WhereClause END IF LEN(@OrderBy) > 0 BEGIN SET @SQL = @SQL + ' ORDER BY ' + @OrderBy END -- Populate the temp table exec sp_executesql @SQL -- Return paged results SELECT O.[ProductID], O.[ProductName] FROM dbo.[Products] O, #PageIndex PageIndex WHERE PageIndex.IndexID > @PageLowerBound AND O.[ProductID] = PageIndex.[ProductID] ORDER BY PageIndex.IndexID -- get row count SET @SQL = 'SELECT @RtnCount = COUNT(ProductID)' SET @SQL = @SQL + ' FROM dbo.[Products]' IF LEN(@WhereClause) > 0 BEGIN SET @SQL = @SQL + ' WHERE ' + @WhereClause END EXEC SP_EXECUTESQL @SQL, N'@WhereClause varchar(2000),@RtnCount int OUTPUT', @WhereClause, @RtnCount = @ItemCount OUTPUT ENDGO