1)
ALTER PROCEDURE [dbo].[up_PageTemplatePageList] @PageSize INT, @PageIndex INT, @TempleteType INT, @TemplateName VARCHAR(50)='', @TemplateFileName VARCHAR(50)='', @ReturnCount INT OUTPUT AS BEGIN SELECT @ReturnCount=COUNT(1) FROM PageTemplate WHERE TempleteType=(CASE WHEN @TempleteType=0 THEN TempleteType ELSE @TempleteType END) AND TemplateName LIKE @TemplateName AND TemplateFileName LIKE @TemplateFileName; WITH TempLatePageList AS ( SELECT ROW_NUMBER() OVER(ORDER BY OrderNum DESC) RowIndex,* FROM PageTemplate WHERE TempleteType=(CASE WHEN @TempleteType=0 THEN TempleteType ELSE @TempleteType END) AND TemplateName LIKE @TemplateName AND TemplateFileName LIKE @TemplateFileName ) SELECT * FROM TempLatePageList WHERE RowIndex BETWEEN @PageSize*(@PageIndex-1)+1 AND @PageSize*@PageIndex END

2)
ALTER PROCEDURE [dbo].[up_PageTemplatePageListByTemplateType]
	@PageSize int,
	@PageIndex int,
	@TempleteType int,
	@TemplateName varchar(50)='',
	@TemplateFileName varchar(50)='',
	@ReturnCount int output
AS
BEGIN
	declare @where varchar(50)
	declare @sqlfragment nvarchar(max)
	declare @strCount nvarchar(1000)
	set @where=''
	SET NOCOUNT ON;
	BEGIN	
		if(@TempleteType<>0)
		begin
	      	set @strCount='set @num=(select COUNT(TemplateId) 
		                         from PageTemplate 
		                         where TempleteType='+@TempleteType+' AND TemplateName LIKE '''+@TemplateName 
		                               +''' AND TemplateFileName LIKE '''+@TemplateFileName+''')'
		end
		else
		begin
	    	set @strCount='set @num=(select COUNT(TemplateId) from PageTemplate)'
		end
		
		EXECUTE sp_executesql @strCount ,N'@num INT output',@ReturnCount output
	END 
	begin
		if(@TempleteType<>0)
		begin
		set @sqlfragment=' select top ('+@pageSize+') *
							 from PageTemplate 
							where TempleteType='+@TempleteType+' AND TemplateName LIKE '''+@TemplateName 
	                               +''' AND TemplateFileName LIKE '''+@TemplateFileName+'''
							and TemplateId not in (select top ('+str((@pageIndex-1)*@pageSize)+') TemplateId 
							                  from PageTemplate where TempleteType='+@TempleteType+
											+' AND TemplateName LIKE '''+@TemplateName 
	                               +''' AND TemplateFileName LIKE '''+@TemplateFileName+''' order by OrderNum desc
	                               ) order by OrderNum desc'
		end
		else
		begin
			set @sqlfragment=' select top ('+str(@pageSize*@pageIndex)+') *
							 from PageTemplate 
							where TempleteType=TempleteType AND TemplateName LIKE '''+@TemplateName 
	                               +''' AND TemplateFileName LIKE '''+@TemplateFileName+''' 
	                                  and TemplateId not in 
	                                    (select top ('+str((@pageIndex-1)*@pageSize)+') TemplateId
	                                          from PageTemplate where TempleteType=TempleteType AND TemplateName LIKE '''+@TemplateName 
	                               +''' AND TemplateFileName LIKE '''+@TemplateFileName+''' order by OrderNum desc) order by OrderNum desc'
		end

	end
	--print('@sqlfragment:'+@sqlfragment)
	exec(@sqlfragment)
	
END