[SQL 2012] Funções OFFSET FECTH
Novas funções do SQL Server 2012
Uma nova função do SQL Server 2012 veio para ajudar na paginação de ResultSets.
Antes tÃnhamos que usar comandos como row_number, cursores, CTE, etc.
Agora vamos utilizar o comando OFFSET/FETCH
OFFSET vai determinar quantos registros devemos saltar e o FETCH quantos registros retornar.
Criando ambiente de teste:
CREATE TABLE ClientePag
(
  ID int identity primary key,
  Nome varchar(100)
)
GO
INSERT INTO ClientePag VALUES(NEWID())
GO 100
Vamos criar uma procedure para facilitar esta paginação:
CREATE PROCEDURE usp_Paginar
(
  @Inicial INT,
  @Quantidade INT
)
AS
SELECT * FROM ClientePag ORDER BY ID
OFFSET ((@Inicial - 1) * @Quantidade) ROWS
FETCH NEXT @Quantidade ROWS ONLY
GO
Vamos testar a procedure:
exec usp_Paginar 1,4
exec usp_Paginar 2,4
exec usp_Paginar 3,4
exec usp_Paginar 4,4
Â

Agora basta implementar isso na sua aplicação.
Related articles
How to call a function inside my SQL Server?
Database function function and function
How to create an SQL to do multiple inserts in one statement?
Practical examples
Short: SQL Update using begin try and begin transaction
Commit and Rollback command
Ozimar Henrique