About the author

The author is just another obsessive compulsive hacker (the good kind) who when confronted with anything new can't help but wonder "how'd they do that?!?"

By day, I'm the Software Architect for CBMC; by night, I just try to "keep the clients happy" as Director of Technology for sdgInteractive.


MCPD

RSS Feed

Server Side Paging with Common Table Expressions

by hilkiah 28. August 2007 22:08

It's times like this that I feel like I don't read enough . . . Apparently SQL Server 2005 added a great new concept called a Common Table Expression (CTE) based on the ANSI SQL-99 standard. Essentially, these allow you to create an on-the-fly view that lives only in the scope of the currently executing query much the same way as previously done with temp tables. However, with CTEs you don't have to create and popuplate the temp table - you just you just have to create the definition and then query against it just you would any other table. Add the ability for self-referencing and you have a handy new tool for writing tight routines to solve some of your more complex query requirements. I came across this in an article by Jacob Sebastian on SqlServerCentral.com showing a technique for using a CTE to create a server side paging routine. I wrote something along these lines a while back for a project I was working on that used a temporary table technique with most of the features Jacob demonstrates but using 3 to 4 times the code. I really like this new approach! After reading his article, I went off researching CTEs trying to get a handle on what they were and how they worked. I ran across another great article by Steve Manik on SQLServerPerformance.com that provides a very nice walkthrough and overview for getting started on the possibilities!

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags:

SQL Server