O'Reilly logo

Programming Microsoft® SQL Server® 2012 by Leonard Lobel and Andrew Brust

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

New T-SQL Functions in SQL Server 2012

The latest version of SQL Server augments T-SQL with many new functions. In this section, we cover the 22 new functions (and 1 changed function) introduced in SQL Server 2012. We’ll start by covering the new T-SQL analytic functions, because they operate using the same windowing principles we were just discussing.

New Analytic Functions

Eight new analytic functions have been added to T-SQL. All of them work in conjunction with an ordered window defined with an associated ORDER BY clause that can be optionally partitioned with a PARTITION BY clause and framed with a BETWEEN clause. The new functions are:

  • FIRST_VALUE

  • LAST_VALUE

  • LAG

  • LEAD

  • PERCENT_RANK

  • CUME_DIST

  • PERCENTILE_CONT

  • PERCENTILE_DISC

In Example 2-32, the FIRST_VALUE, ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required