The SQL Server 2012 code named "Denali" has lot of new feature. In this article I am trying to explain a new feature of SQL Server 2012 called "Ad-Hoc Query Preparing"
The ORDER BY clause of SELECT statement has been enhanced by SQL Server 2012 by using the combination of OFFSET and FETCH. OFFSET and FETCH along with ORDER BY gives us the option to paging through the result set.
The OFFSET clauses specifies the numbers of rows to skip before returning the query and the FEATCH specifies the numbers of rows to return after OFFSET clause has been proceed.
Let's takes an example to understand it properly.
Suppose we have a table named TABLE-A. The structure of the TABLE-A is mentioned bellow. The TABLE-A Contains more then 10,000 records.
STUDNAME | STUCLASS |
JOYDEEP DAS | 1 |
PALASH KANTI PAUL | 1 |
SUDIP DAS | 1 |
TUHIN KUMAR SHINAH | 1 |
SANGRAM JIT BHATTERCHARYA | 1 |
N th … |
|
Now we want to display the result set like this.
First remove the 10 records and from 11th to next 10 records to be displayed in the result set.
Frist I am providing a query that supports SQL 2005 to display the desired result st using CTE.
WITH stud(stuname, stuclass, rowNUM)
AS
(SELECT Row_number() OVER (ORDER BY p.stuname) AS rowNUM,
stuname, stucalss
FROM TABLE-A p
)SELECT *
FROM stud p
WHERE p.rowNUM BETWEEN 11 AND 20
It is quite complicated for the developer who uses the SQL Server 2012…. What you think?
So now I am providing you the new Example using OFSET and FEATCH NEXT feature of SQL 2012.
SELECT p.stuname, p.stuclass
FROM TABLE-A p
ORDER BY p.stuname
OFFSET 10 rows
FETCH NEXT 10 rows only
So it is so easy now with SQL Server 2012.
Hope you like it.
Posted by: MR. JOYDEEP DAS
Mardin
ReplyDeleteistanbul
Çanakkale
Antep
Elazığ
A0EA
Erzurum
ReplyDeleteElazığ
Konya
Zonguldak
Eskişehir
EUN8S
Diyarbakır
ReplyDeleteSamsun
Antep
Kırşehir
Konya
1YX3
whatsapp görüntülü show
ReplyDeleteücretli.show
LKA55
ankara parça eşya taşıma
ReplyDeletetakipçi satın al
antalya rent a car
antalya rent a car
ankara parça eşya taşıma
ZİQ
siirt evden eve nakliyat
ReplyDeleteadıyaman evden eve nakliyat
kastamonu evden eve nakliyat
artvin evden eve nakliyat
malatya evden eve nakliyat
VOXVC8
siirt evden eve nakliyat
ReplyDeleteadıyaman evden eve nakliyat
kastamonu evden eve nakliyat
artvin evden eve nakliyat
malatya evden eve nakliyat
İUFT
48D73
ReplyDeleteTrabzon Evden Eve Nakliyat
Yozgat Evden Eve Nakliyat
Bitlis Evden Eve Nakliyat
Van Evden Eve Nakliyat
Mersin Evden Eve Nakliyat
4431B
ReplyDeletebuy fat burner
primobolan for sale
order pharmacy steroids
sarms
anapolon oxymetholone
Bartın Evden Eve Nakliyat
Sinop Evden Eve Nakliyat
order steroids
Çanakkale Evden Eve Nakliyat
7F58D
ReplyDeleteadana yabancı sohbet
bingöl sesli sohbet mobil
rastgele canlı sohbet
antep canlı görüntülü sohbet odaları
manisa canli goruntulu sohbet siteleri
afyon rastgele sohbet
sesli sohbet sesli chat
kırıkkale canlı sohbet ücretsiz
görüntülü sohbet ücretsiz
A0142
ReplyDeleteMith Coin Hangi Borsada
Onlyfans Beğeni Satın Al
Mexc Borsası Kimin
Alyattes Coin Hangi Borsada
Osmo Coin Hangi Borsada
Kripto Para Kazma
Bitcoin Nasıl Üretilir
Discord Sunucu Üyesi Satın Al
Binance Referans Kodu
0BA88
ReplyDeleteFacebook Takipçi Satın Al
Expanse Coin Hangi Borsada
Periscope Beğeni Satın Al
Binance Borsası Güvenilir mi
Kripto Para Madenciliği Nasıl Yapılır
Bitcoin Çıkarma
Binance Hesap Açma
Sohbet
Trovo Takipçi Hilesi