24.8.12

The OFFSET-FETCH Filter in select clause


This is one of the fantastic feature introduced in SQL Server.

As we all know about "Top" Clause. It will filter the data in a specific order.

              Select Top (10) * from Venkat_Table

The above query will fetch top 10 records from the table.

We don't have any provision to avoid a set of data and fetch the next level of data. Here is the provision and it can be done using Offset-Fetch Filter option.

Here is the query format,

create table venkat_Table( id int identity(1,1), val varchar(100))
go
insert into venkat_Table values
('a')
go 25
go
insert into venkat_Table values
('b')
go 25
select * from venkat_Table
GO
select * from venkat_Table
offset 25 rows fetch next 10 rows only


The above query will fetch 10 rows after leaving 25 rows.

Cheers,
Venkatesan Prabu .J
Head, KaaShiv InfoTech

2 comments: