SQL Server 2012 DENALI T-SQL Enhancements: FETCH & OFFSET

Who is online?  99 guests and 0 members
home  »  blogs  »  Raunak Jhawar  »  SQL Server 2012 DENALI T-SQL Enhancements: FETCH & OFFSET

Training on Microsoft Products & Technologies

  Rate This Blog Entry:  register  or  login

Author

raunak.jhawar Raunak Jhawar (Member since: 7/12/2011 6:42:24 AM)
Specilaist for Intensive Data Computing.

View Raunak Jhawar 's profile

Comments (7)

sarab
11/16/2011 11:03:06 PM Sarabpreet Anand said:

Amazing feature and easy than Cursors and CTEs.

by
raunak.jhawar
11/17/2011 4:23:16 AM Raunak Jhawar said:

Sarab, I do not understand the need of "ONLY" keyword at the end of the SQL statement. This really is not required?

by
sarab
11/18/2011 3:07:25 AM Sarabpreet Anand said:

May be they did it just to make it more readable..... As you know, Microsoft always belived in simplicity and T-SQL is more readable than others.

by
Andy.Vale
11/18/2011 5:34:06 PM Andy Vale said:

Hi Raunak - great post and lovely new Denali feature! Question though, meaning I've probably misunderstood something, but in the original cte we are filtering where current order is between 151 and 350 I.E. 200 rows. However in the translated offset/fetch example we state an offset of 150 and a fetch of 350, would this not give us back 350 rows instead of the 200?

by
raunak.jhawar
11/21/2011 6:54:49 AM Raunak Jhawar said:

Eagle eyes Andy, The SQL is wrongly composed.

select AdventureWorksDWDenali.dbo.DimProduct.EnglishProductName 
       , AdventureWorksDWDenali.dbo.DimProduct.ReorderPoint 
       , AdventureWorksDWDenali.dbo.DimProduct.DealerPrice 
from AdventureWorksDWDenali.dbo.DimProduct 
order by EnglishProductName 
offset 150 rows 
fetch next 200 rows only

Thanks for pointing the error!

Thanks,

Raunak

by
user146939
12/15/2011 5:31:59 AM Rashmi Patankar said:

One more point I would like to raise over here is that while using the CTE we are fetching the rows from 150 to 250 (i.e. a count of 200) whereas in the fetch/offset method, saying offset 150 would start selecting the records from row 151. To select from 150 we will have to specify offset 149.

by
raunak.jhawar
12/15/2011 5:39:10 AM Raunak Jhawar said:

Yes, because the SQL is asking the SQL engine to offset 150 rows and hence the first record will begin from 151. Valid point.

Thanks\Raunak

by

Leave a comment


 
Type the characters:
 *
 
   

Training on Microsoft Products & Technologies

Training on Microsoft Products & Technologies

Email Subscriptions

   Get the Most Recent Blogs in your inbox
Blogs RSS Feed

Raunak Jhawar's latest blog posts

Blogs RSS Feed

Latest community blog posts

  • Dear SQL Geek, SQLServerGeeks.com cordially invites you to SQL Server Day, the monthly dose of SQL Server knowledge & learning. And after successful events in Bangalore, Kolkata & Mumbai, we a...
  • Hi SQL Geeks, The Microsoft® SQL Server® 2012 Feature Pack is a collection of stand-alone packages which provide additional value for Microsoft® SQL Server® 2012. You can download the ...
  • Hi Friends, Here is an interesting function: QUOTENAME() which returns a Unicode string with the delimiters added to make the input string a valid SQL Server delimited identifier. (from Books Online) ...
  • Hi All, It is a great news to all those who use SQL Server Express editions. Microsoft has increased the database size limit of SQL Server 2008 R2 Express edition from 4GB to 10GB. Previous versions o...
  • Hello Friends, It’s been a while that I have posted any blog. So here it is- Well with the arrival of SQL Server 2000, Microsoft has introduced the concept of User Defined Function (UDF). So the...
  • Exciting news! SQL Server 2012 has released to manufacturing. Customers and partners can download an evaluation of the product today and can expect general availability to begin on April 1. Microsoft ...