SlideShare a Scribd company logo
Richie Rump
         @Jorriss
http://jorriss.net
New T-SQL Features in SQL Server 2012
•   Sequences
•   Data Paging
•   Analytic Window Functions
•   Conversion Functions
•   Logical Functions
•   Date/Time Functions
•   String Functions
• New construct to generate numeric
  sequences.
• Ability to set min and max values
• Cycle will set the current value to the min
  value when the max value is reached
• Future values can be cached minimizing
  disk IO.
• Returns metadata for the supplied SQL
  statement.
• Useful for determining column/database
  information for a SQL statement or
  Stored Procedure.
• If set to 0, no information is returned.
• If set to 1, each query is analyzed as if it
  includes a FOR BROWSE option on the query.
  This will return base table names as the
  source column information.
• If set to 2, each query is analyzed as if it
  would be used in preparing or executing a
  cursor. This will return view names as source
  column information.
• Allows the changing of column names
  and data types in the resultset of a
  stored procedure.
• Yes, you can change column names when
  you call a stored procedure.
• Allows for server side paging.
• Not data pages (8K of awesome) but
  paging like on a web page.
• OFFSET AND FETCH are arguments of the
  ORDER BY clause
• OFFSET – Number of rows to skip
• FETCH – Number of rows to return
•   LAG
•   LEAD
•   FIRST_VALUE
•   LAST_VALUE
•   PERCENT_RANK
•   CUME_DIST
•   PERCENTILE_CONT
•   PERCENTILE_DISC
• The OVER clause determines the
  partitions and order of a rowset before
  the window function is applied.

• WHAT CHU TALKING ABOUT WILLIS?
• PARTITON BY – Similar to GROUP BY but
  only applies to the window function and
  not the entire query.
• ORDER BY – Specifies the order of the
  rows in the partition
• No longer need to use a self-join or CTE.
• LAG: Access data from previous rows in
  the result set.
• LEAD: Access data from future rows in
  the result set.
• FIRST_VALUE: Retrieves the first value in
  a partition.
• LAST_VALUE: Retrieves the last value in a
  partition.
• Calculates a relative rank of a row.
• (RANK() – 1) / (Total Rows – 1)
• Calculates the percentage of values less
  than or equal to the current value in the
  group.
• COUNT(*) OVER (ORDER BY Col1) / Total
  Count
• Calculates a percentile value
• Will interpolate the appropriate value
• Can use to find the median
  – PERCENTILE_CONT(0.5)
• CONT stands for continuous
• Calculates a percentile value
• Like PERCENTILE_CONT but will select a
  value that exists in the set.
• Can use to find the median
  – PERCENTILE_CONT(0.5)
• DISC stands for discrete distribution
• Attempts to parse a string and convert it
  to a specified datatype.
• Can only convert to a number or
  datetime
• Uses the .Net CLR
• Like PARSE but if an error occurs returns
  a NULL.
• Still uses the .Net CLR.
• Attempts to cast a value into a specified
  data type. Returns NULL if CONVERT fails.
• Immediate If aka Inline If
• Takes a boolean expression and returns
  one of two values.
• Shorthand for CASE.
• Has the same limitations as CASE
  – Can only be nested to 10 levels
• Returns a value from a list based on a
  specified index.
• If the specified index is not in the list
  NULL is returned.
• Returns the data type based on data type
  precedence.
• Returns last date of a specified month.
• Can specify a month_to_add argument
  to increment or decrement result.
• DATEFROMPARTS ( year, month, day)
• DATETIME2FROMPARTS ( year, month, day, hour, minute,
  seconds, fractions, precision )
• DATETIMEFROMPARTS ( year, month, day, hour, minute,
  seconds, milliseconds )
• DATETIMEOFFSETFROMPARTS ( year, month, day, hour,
  minute, seconds, fractions, hour_offset, minute_offset,
  precision )
• SMALLDATETIMEFROMPARTS ( year, month, day, hour,
  minute )
• TIMEFROMPARTS ( hour, minute, seconds, fractions,
  precision )
• Does what it says…concatenates strings
  together.
• NULLs are automatically converted to
  empty strings.
• Can pass other data types for
  concatenation.
• Simplifies the string formatting of dates
  and other data types.
• No more memorizing numeric predefined
  format values.
• Returns a string.
• Uses .Net CLR
• Reduces the need to use RAISERROR in
  TRY/CATCH blocks.
• Can provide custom error messages.
• Always uses severity level 16.
New T-SQL Features in SQL Server 2012
Richie Rump
@Jorriss
jorriss@gmail.com
http://jorriss.net
http://dotnetmiami.com
New T-SQL Features in SQL Server 2012
Denali T-SQL at a Glance - New and Enhanced Functions
http://www.sqlmag.com/blog/puzzled-by-t-sql-blog-15/tsql/denali-tsql-glance-enhanced-
functions-140785

T-SQL Improvements in SQL Server 2012
http://www.infoq.com/news/2012/03/T-SQL-2012

SQL SERVER – Denali – 14 New Functions – A Quick Guide
http://blog.sqlauthority.com/2011/09/21/sql-server-denali-14-new-functions-a-quick-
guide/

Performance Test of New Date Manipulation Functions (SQL Spackle)
http://www.sqlservercentral.com/articles/Performance/89505/

Keyboard Shortcuts in Visual Studio 2012. Need to import settings.
http://www.mssqltips.com/sqlservertip/2625/improvement-to-keyboard-shortcuts-in-sql-
server-2012-management-studio/
• MSDN: http://msdn.microsoft.com/en-
  us/library/ff878091.aspx
• Sequence: Why they aren’t just for surrogate keys:
  http://blog.infoadvisors.com/index.php/2012/02/16
  /new-in-sql-server-2012-sequences-why-they-arent-
  just-for-surrogate-keys/
• Sequence in 2012: http://www.sql-server-
  performance.com/2011/sequence-sql-server-2011/
• Create Sequence: http://www.dbadiaries.com/new-
  t-sql-features-in-sql-server-2012-create-sequence/
• MSDN: http://msdn.microsoft.com/en-
  us/library/ff878602.aspx
• http://blog.sqlauthority.com/2012/03/31
  /sql-server-sp_describe_first_result_set-
  new-system-stored-procedure-in-sql-
  server-2012/
• MSDN: http://msdn.microsoft.com/en-
  us/library/ms188332.aspx
• WITH RESULT SETS
  http://www.dbadiaries.com/new-t-sql-
  features-in-sql-server-2012-with-result-
  sets/
• MSDN: http://msdn.microsoft.com/en-
  us/library/ms188385.aspx
• TSQL 2012 – OFFSET and FETCH:
  http://stevestedman.com/2012/04/tsql-2012-
  offset-and-fetch/
• OFFSET and FETCH:
  http://www.dbadiaries.com/new-t-sql-
  features-in-sql-server-2012-offset-and-fetch/
• LAG - MSDN: http://msdn.microsoft.com/en-
  us/library/hh231256
• LEAD - MSDN: http://msdn.microsoft.com/en-
  us/library/hh213125
• FIRST_VALUE - MSDN:
  http://msdn.microsoft.com/en-
  us/library/hh213018
• LAST_VALUE - MSDN:
  http://msdn.microsoft.com/en-
  us/library/hh231517
• MSDN: http://msdn.microsoft.com/en-
  us/library/hh213573.aspx
• Introduction to PERCENT_RANK():
  http://blog.sqlauthority.com/2011/11/18/sql-
  server-introduction-to-percent_rank-analytic-
  functions-introduced-in-sql-server-2012/
• MSDN: http://technet.microsoft.com/en-
  us/library/hh231078.aspx
• Introduction to CUME_DIST:
  http://blog.sqlauthority.com/2011/11/08/sql-
  server-introduction-to-cume_dist-analytic-
  functions-introduced-in-sql-server-2012/
• PERCENTILE_CONT - MSDN:
  http://msdn.microsoft.com/en-
  us/library/hh231473.aspx
• Introduction to PERCENTILE_CONT:
  http://blog.sqlauthority.com/2011/11/20/sql-
  server-introduction-to-percentile_cont-analytic-
  functions-introduced-in-sql-server-2012/
• What exactly does PERCENTILE_CONT do?
  http://www.sqlskills.com/BLOGS/BOBB/post/Wh
  at-exactly-does-PERCENTILE_CONT-do-
  anyhow.aspx
• PERCENTILE_DISC - MSDN:
  http://msdn.microsoft.com/en-
  us/library/hh231327
• Introduction to PERCENTILE_DISC:
  http://blog.sqlauthority.com/2011/11/22/sql-
  server-introduction-to-percentile_disc-
  analytic-functions-introduced-in-sql-server-
  2012/
• Difference between PARSE(), TRY_PARSE(),
  TRY_CONVERT():
  http://blog.sqlauthority.com/2011/09/09/sql-server-
  denali-conversion-function-difference-between-parse-
  try_parse-try_convert/
• PARSE - MSDN: http://msdn.microsoft.com/en-
  us/library/hh213316.aspx
• TRY_PARSE - MSDN: http://msdn.microsoft.com/en-
  us/library/hh974669
• TRY_CONVERT - MSDN:
  http://msdn.microsoft.com/en-us/library/hh230993
• MSDN: http://msdn.microsoft.com/en-
  us/library/hh213574.aspx
• MSDN: http://msdn.microsoft.com/en-
  us/library/hh213019
• CHOOSE() – A Quick Introduction:
  http://blog.sqlauthority.com/2011/09/11/sql-
  server-denali-logical-function-choose-a-quick-
  introduction/
• MSDN: http://msdn.microsoft.com/en-
  us/library/hh213020.aspx
• EOMONTH() – A Quick Introduction:
  http://blog.sqlauthority.com/2011/09/20/sql-
  server-denali-date-and-time-functions-
  eomonth-a-quick-introduction/
• A Quick Introduction:
  http://blog.sqlauthority.com/2011/09/19/sql-
  server-denali-date-and-time-functions-
  datefromparts-datetimefromparts-
  datetime2fromparts-timefromparts-
  smalldatetimefromparts-
  datetimeoffsetfromparts-a-quick-introduc/
• MSDN: http://msdn.microsoft.com/en-
  us/library/hh231515.aspx
• MSDN: http://msdn.microsoft.com/en-
  us/library/hh213505.aspx
• New SQL Server Function to Format Dates:
  http://www.mssqltips.com/sqlservertip/2655/ne
  w-sql-server-function-to-format-
  dates/?utm_source=dailynewsletter&utm_mediu
  m=email&utm_content=headline&utm_campaig
  n=2012427
• Custom Numeric Formats -
  http://msdn.microsoft.com/en-
  US/library/0c899ak8.aspx#SpecifierD
• http://www.dbadiaries.com/new-t-sql-
  features-in-sql-server-2012-throw/

More Related Content

What's hot (20)

ODP
Oracle SQL Advanced
Dhananjay Goel
 
ODP
SQL Tunning
Dhananjay Goel
 
PPTX
Intro to T-SQL - 1st session
Medhat Dawoud
 
PPTX
Oraclesql
Priya Goyal
 
PPTX
MySQL Replication Evolution -- Confoo Montreal 2017
Dave Stokes
 
PPT
Sql server T-sql basics ppt-3
Vibrant Technologies & Computers
 
PPT
ORACLE PL SQL
Srinath Maharana
 
PDF
SQL
kaushal123
 
PPTX
Getting Started with MySQL I
Sankhya_Analytics
 
PDF
PostgreSQL Tutorial For Beginners | Edureka
Edureka!
 
PPT
MySql slides (ppt)
webhostingguy
 
PDF
Mysql Explain Explained
Jeremy Coates
 
PPTX
Introduction to SQL, SQL*Plus
Chhom Karath
 
PPTX
Recipes 6 of Data Warehouse and Business Intelligence - Naming convention tec...
Massimo Cenci
 
PPTX
Getting Started with MySQL II
Sankhya_Analytics
 
PPTX
ata Warehouse and Business Intelligence - Recipe 7 - A messaging system for O...
Massimo Cenci
 
PPTX
Database COMPLETE
Abrar ali
 
PPT
SQL Server 2008 Performance Enhancements
infusiondev
 
PPT
SQL- Introduction to PL/SQL
Vibrant Technologies & Computers
 
PPTX
Oracle Data Redaction
Alex Zaballa
 
Oracle SQL Advanced
Dhananjay Goel
 
SQL Tunning
Dhananjay Goel
 
Intro to T-SQL - 1st session
Medhat Dawoud
 
Oraclesql
Priya Goyal
 
MySQL Replication Evolution -- Confoo Montreal 2017
Dave Stokes
 
Sql server T-sql basics ppt-3
Vibrant Technologies & Computers
 
ORACLE PL SQL
Srinath Maharana
 
Getting Started with MySQL I
Sankhya_Analytics
 
PostgreSQL Tutorial For Beginners | Edureka
Edureka!
 
MySql slides (ppt)
webhostingguy
 
Mysql Explain Explained
Jeremy Coates
 
Introduction to SQL, SQL*Plus
Chhom Karath
 
Recipes 6 of Data Warehouse and Business Intelligence - Naming convention tec...
Massimo Cenci
 
Getting Started with MySQL II
Sankhya_Analytics
 
ata Warehouse and Business Intelligence - Recipe 7 - A messaging system for O...
Massimo Cenci
 
Database COMPLETE
Abrar ali
 
SQL Server 2008 Performance Enhancements
infusiondev
 
SQL- Introduction to PL/SQL
Vibrant Technologies & Computers
 
Oracle Data Redaction
Alex Zaballa
 

Viewers also liked (20)

PDF
Top 5 TSQL Improvements in SQL Server 2014
Boris Hristov
 
PPTX
SQL Saturday 329 - Novo Cardinality Estimator do SQL Server 2014
Vitor Fava
 
PDF
Running SQL 2005? It’s time to migrate to SQL 2014!
Dell World
 
PPTX
Deep Into Isolation Levels
Boris Hristov
 
PPTX
Mastering T-SQL Window Functions
Jose Rivera Miranda
 
PDF
Sql server windowing functions
Enrique Catala Bañuls
 
PDF
Tutorial SAP: Instalación sap bo 4.0
Oreka IT
 
PPTX
Leveraging memory in sql server
Chris Adkin
 
PPTX
SQL Server 2012 Certifications
Marcos Freccia
 
DOC
Sql server-dba
NaviSoft
 
PDF
Window functions with SQL Server 2016
Mark Tabladillo
 
PPTX
SQL Server 2014 New Features
Onomi
 
DOCX
Sql Server Interview Question
pukal rani
 
PPT
SQL Server Transaction Management
Mark Ginnebaugh
 
PDF
Sql server 2008 interview questions answers
Jitendra Gangwar
 
PPTX
Sql server 2012 dba online training
sqlmasters
 
PPTX
Exploring Advanced SQL Techniques Using Analytic Functions
Zohar Elkayam
 
PDF
Data Quality Services in SQL Server 2012
Stéphane Fréchette
 
PPTX
70-461 Querying Microsoft SQL Server 2012
siphocha
 
PPTX
Interview Question and Answers: The internal interview top 10 tips
Practically Perfect PA
 
Top 5 TSQL Improvements in SQL Server 2014
Boris Hristov
 
SQL Saturday 329 - Novo Cardinality Estimator do SQL Server 2014
Vitor Fava
 
Running SQL 2005? It’s time to migrate to SQL 2014!
Dell World
 
Deep Into Isolation Levels
Boris Hristov
 
Mastering T-SQL Window Functions
Jose Rivera Miranda
 
Sql server windowing functions
Enrique Catala Bañuls
 
Tutorial SAP: Instalación sap bo 4.0
Oreka IT
 
Leveraging memory in sql server
Chris Adkin
 
SQL Server 2012 Certifications
Marcos Freccia
 
Sql server-dba
NaviSoft
 
Window functions with SQL Server 2016
Mark Tabladillo
 
SQL Server 2014 New Features
Onomi
 
Sql Server Interview Question
pukal rani
 
SQL Server Transaction Management
Mark Ginnebaugh
 
Sql server 2008 interview questions answers
Jitendra Gangwar
 
Sql server 2012 dba online training
sqlmasters
 
Exploring Advanced SQL Techniques Using Analytic Functions
Zohar Elkayam
 
Data Quality Services in SQL Server 2012
Stéphane Fréchette
 
70-461 Querying Microsoft SQL Server 2012
siphocha
 
Interview Question and Answers: The internal interview top 10 tips
Practically Perfect PA
 
Ad

Similar to New T-SQL Features in SQL Server 2012 (20)

PPTX
Exciting Features for SQL Devs in SQL 2012
Brij Mishra
 
PPTX
SQL Server2012 Enhancements
Abhishek Sur
 
PPTX
New Features of SQL Server 2016
Mir Mahmood
 
PPTX
SQL Windowing
Sandun Perera
 
PDF
Difference between sql server 2008 and sql server 2012
Umar Ali
 
PPTX
Simplifying SQL with CTE's and windowing functions
Clayton Groom
 
PPTX
SQL Server Select Topics
Jay Coskey
 
PPTX
TSQL Functions (SQL Server)
Steve Stedman
 
PPTX
Modern sql
Elizabeth Smith
 
PPSX
Analytic & Windowing functions in oracle
Logan Palanisamy
 
PPTX
SQL Server 2012 Best Practices
Microsoft TechNet - Belgium and Luxembourg
 
PPTX
What's new in SQL Server Integration Services 2012?
Microsoft TechNet - Belgium and Luxembourg
 
PPTX
New features of SQL 2012
Mindfire Solutions
 
PDF
T sql denali code Day of .Net
KathiK58
 
PPTX
Do You Have the Time
Michael Antonovich
 
PPTX
TSQL in SQL Server 2012
Eduardo Castro
 
PDF
advance-sqaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaal.pdf
traphuong2103
 
PPT
Ms sql server architecture
Ajeet Singh
 
PDF
You can do THAT without Perl?
PostgreSQL Experts, Inc.
 
PPTX
Sql good practices
Deepak Mehtani
 
Exciting Features for SQL Devs in SQL 2012
Brij Mishra
 
SQL Server2012 Enhancements
Abhishek Sur
 
New Features of SQL Server 2016
Mir Mahmood
 
SQL Windowing
Sandun Perera
 
Difference between sql server 2008 and sql server 2012
Umar Ali
 
Simplifying SQL with CTE's and windowing functions
Clayton Groom
 
SQL Server Select Topics
Jay Coskey
 
TSQL Functions (SQL Server)
Steve Stedman
 
Modern sql
Elizabeth Smith
 
Analytic & Windowing functions in oracle
Logan Palanisamy
 
SQL Server 2012 Best Practices
Microsoft TechNet - Belgium and Luxembourg
 
What's new in SQL Server Integration Services 2012?
Microsoft TechNet - Belgium and Luxembourg
 
New features of SQL 2012
Mindfire Solutions
 
T sql denali code Day of .Net
KathiK58
 
Do You Have the Time
Michael Antonovich
 
TSQL in SQL Server 2012
Eduardo Castro
 
advance-sqaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaal.pdf
traphuong2103
 
Ms sql server architecture
Ajeet Singh
 
You can do THAT without Perl?
PostgreSQL Experts, Inc.
 
Sql good practices
Deepak Mehtani
 
Ad

Recently uploaded (20)

PPTX
MSP360 Backup Scheduling and Retention Best Practices.pptx
MSP360
 
PDF
Blockchain Transactions Explained For Everyone
CIFDAQ
 
PDF
Fl Studio 24.2.2 Build 4597 Crack for Windows Free Download 2025
faizk77g
 
PDF
Complete Network Protection with Real-Time Security
L4RGINDIA
 
PPTX
Webinar: Introduction to LF Energy EVerest
DanBrown980551
 
PPTX
WooCommerce Workshop: Bring Your Laptop
Laura Hartwig
 
PDF
How Startups Are Growing Faster with App Developers in Australia.pdf
India App Developer
 
PDF
Smart Air Quality Monitoring with Serrax AQM190 LITE
SERRAX TECHNOLOGIES LLP
 
PDF
Building Resilience with Digital Twins : Lessons from Korea
SANGHEE SHIN
 
PDF
NewMind AI - Journal 100 Insights After The 100th Issue
NewMind AI
 
PDF
LLMs.txt: Easily Control How AI Crawls Your Site
Keploy
 
PDF
Transcript: New from BookNet Canada for 2025: BNC BiblioShare - Tech Forum 2025
BookNet Canada
 
PDF
SFWelly Summer 25 Release Highlights July 2025
Anna Loughnan Colquhoun
 
PDF
Smart Trailers 2025 Update with History and Overview
Paul Menig
 
PPTX
Building Search Using OpenSearch: Limitations and Workarounds
Sease
 
PDF
Complete JavaScript Notes: From Basics to Advanced Concepts.pdf
haydendavispro
 
PPT
Interview paper part 3, It is based on Interview Prep
SoumyadeepGhosh39
 
PPTX
✨Unleashing Collaboration: Salesforce Channels & Community Power in Patna!✨
SanjeetMishra29
 
PDF
HubSpot Main Hub: A Unified Growth Platform
Jaswinder Singh
 
PDF
TrustArc Webinar - Data Privacy Trends 2025: Mid-Year Insights & Program Stra...
TrustArc
 
MSP360 Backup Scheduling and Retention Best Practices.pptx
MSP360
 
Blockchain Transactions Explained For Everyone
CIFDAQ
 
Fl Studio 24.2.2 Build 4597 Crack for Windows Free Download 2025
faizk77g
 
Complete Network Protection with Real-Time Security
L4RGINDIA
 
Webinar: Introduction to LF Energy EVerest
DanBrown980551
 
WooCommerce Workshop: Bring Your Laptop
Laura Hartwig
 
How Startups Are Growing Faster with App Developers in Australia.pdf
India App Developer
 
Smart Air Quality Monitoring with Serrax AQM190 LITE
SERRAX TECHNOLOGIES LLP
 
Building Resilience with Digital Twins : Lessons from Korea
SANGHEE SHIN
 
NewMind AI - Journal 100 Insights After The 100th Issue
NewMind AI
 
LLMs.txt: Easily Control How AI Crawls Your Site
Keploy
 
Transcript: New from BookNet Canada for 2025: BNC BiblioShare - Tech Forum 2025
BookNet Canada
 
SFWelly Summer 25 Release Highlights July 2025
Anna Loughnan Colquhoun
 
Smart Trailers 2025 Update with History and Overview
Paul Menig
 
Building Search Using OpenSearch: Limitations and Workarounds
Sease
 
Complete JavaScript Notes: From Basics to Advanced Concepts.pdf
haydendavispro
 
Interview paper part 3, It is based on Interview Prep
SoumyadeepGhosh39
 
✨Unleashing Collaboration: Salesforce Channels & Community Power in Patna!✨
SanjeetMishra29
 
HubSpot Main Hub: A Unified Growth Platform
Jaswinder Singh
 
TrustArc Webinar - Data Privacy Trends 2025: Mid-Year Insights & Program Stra...
TrustArc
 

New T-SQL Features in SQL Server 2012

  • 1. Richie Rump @Jorriss http://jorriss.net
  • 3. Sequences • Data Paging • Analytic Window Functions • Conversion Functions • Logical Functions • Date/Time Functions • String Functions
  • 4. • New construct to generate numeric sequences. • Ability to set min and max values • Cycle will set the current value to the min value when the max value is reached • Future values can be cached minimizing disk IO.
  • 5. • Returns metadata for the supplied SQL statement. • Useful for determining column/database information for a SQL statement or Stored Procedure.
  • 6. • If set to 0, no information is returned. • If set to 1, each query is analyzed as if it includes a FOR BROWSE option on the query. This will return base table names as the source column information. • If set to 2, each query is analyzed as if it would be used in preparing or executing a cursor. This will return view names as source column information.
  • 7. • Allows the changing of column names and data types in the resultset of a stored procedure. • Yes, you can change column names when you call a stored procedure.
  • 8. • Allows for server side paging. • Not data pages (8K of awesome) but paging like on a web page. • OFFSET AND FETCH are arguments of the ORDER BY clause • OFFSET – Number of rows to skip • FETCH – Number of rows to return
  • 9. LAG • LEAD • FIRST_VALUE • LAST_VALUE • PERCENT_RANK • CUME_DIST • PERCENTILE_CONT • PERCENTILE_DISC
  • 10. • The OVER clause determines the partitions and order of a rowset before the window function is applied. • WHAT CHU TALKING ABOUT WILLIS?
  • 11. • PARTITON BY – Similar to GROUP BY but only applies to the window function and not the entire query. • ORDER BY – Specifies the order of the rows in the partition
  • 12. • No longer need to use a self-join or CTE. • LAG: Access data from previous rows in the result set. • LEAD: Access data from future rows in the result set.
  • 13. • FIRST_VALUE: Retrieves the first value in a partition. • LAST_VALUE: Retrieves the last value in a partition.
  • 14. • Calculates a relative rank of a row. • (RANK() – 1) / (Total Rows – 1)
  • 15. • Calculates the percentage of values less than or equal to the current value in the group. • COUNT(*) OVER (ORDER BY Col1) / Total Count
  • 16. • Calculates a percentile value • Will interpolate the appropriate value • Can use to find the median – PERCENTILE_CONT(0.5) • CONT stands for continuous
  • 17. • Calculates a percentile value • Like PERCENTILE_CONT but will select a value that exists in the set. • Can use to find the median – PERCENTILE_CONT(0.5) • DISC stands for discrete distribution
  • 18. • Attempts to parse a string and convert it to a specified datatype. • Can only convert to a number or datetime • Uses the .Net CLR
  • 19. • Like PARSE but if an error occurs returns a NULL. • Still uses the .Net CLR.
  • 20. • Attempts to cast a value into a specified data type. Returns NULL if CONVERT fails.
  • 21. • Immediate If aka Inline If • Takes a boolean expression and returns one of two values. • Shorthand for CASE. • Has the same limitations as CASE – Can only be nested to 10 levels
  • 22. • Returns a value from a list based on a specified index. • If the specified index is not in the list NULL is returned. • Returns the data type based on data type precedence.
  • 23. • Returns last date of a specified month. • Can specify a month_to_add argument to increment or decrement result.
  • 24. • DATEFROMPARTS ( year, month, day) • DATETIME2FROMPARTS ( year, month, day, hour, minute, seconds, fractions, precision ) • DATETIMEFROMPARTS ( year, month, day, hour, minute, seconds, milliseconds ) • DATETIMEOFFSETFROMPARTS ( year, month, day, hour, minute, seconds, fractions, hour_offset, minute_offset, precision ) • SMALLDATETIMEFROMPARTS ( year, month, day, hour, minute ) • TIMEFROMPARTS ( hour, minute, seconds, fractions, precision )
  • 25. • Does what it says…concatenates strings together. • NULLs are automatically converted to empty strings. • Can pass other data types for concatenation.
  • 26. • Simplifies the string formatting of dates and other data types. • No more memorizing numeric predefined format values. • Returns a string. • Uses .Net CLR
  • 27. • Reduces the need to use RAISERROR in TRY/CATCH blocks. • Can provide custom error messages. • Always uses severity level 16.
  • 31. Denali T-SQL at a Glance - New and Enhanced Functions http://www.sqlmag.com/blog/puzzled-by-t-sql-blog-15/tsql/denali-tsql-glance-enhanced- functions-140785 T-SQL Improvements in SQL Server 2012 http://www.infoq.com/news/2012/03/T-SQL-2012 SQL SERVER – Denali – 14 New Functions – A Quick Guide http://blog.sqlauthority.com/2011/09/21/sql-server-denali-14-new-functions-a-quick- guide/ Performance Test of New Date Manipulation Functions (SQL Spackle) http://www.sqlservercentral.com/articles/Performance/89505/ Keyboard Shortcuts in Visual Studio 2012. Need to import settings. http://www.mssqltips.com/sqlservertip/2625/improvement-to-keyboard-shortcuts-in-sql- server-2012-management-studio/
  • 32. • MSDN: http://msdn.microsoft.com/en- us/library/ff878091.aspx • Sequence: Why they aren’t just for surrogate keys: http://blog.infoadvisors.com/index.php/2012/02/16 /new-in-sql-server-2012-sequences-why-they-arent- just-for-surrogate-keys/ • Sequence in 2012: http://www.sql-server- performance.com/2011/sequence-sql-server-2011/ • Create Sequence: http://www.dbadiaries.com/new- t-sql-features-in-sql-server-2012-create-sequence/
  • 33. • MSDN: http://msdn.microsoft.com/en- us/library/ff878602.aspx • http://blog.sqlauthority.com/2012/03/31 /sql-server-sp_describe_first_result_set- new-system-stored-procedure-in-sql- server-2012/
  • 34. • MSDN: http://msdn.microsoft.com/en- us/library/ms188332.aspx • WITH RESULT SETS http://www.dbadiaries.com/new-t-sql- features-in-sql-server-2012-with-result- sets/
  • 35. • MSDN: http://msdn.microsoft.com/en- us/library/ms188385.aspx • TSQL 2012 – OFFSET and FETCH: http://stevestedman.com/2012/04/tsql-2012- offset-and-fetch/ • OFFSET and FETCH: http://www.dbadiaries.com/new-t-sql- features-in-sql-server-2012-offset-and-fetch/
  • 36. • LAG - MSDN: http://msdn.microsoft.com/en- us/library/hh231256 • LEAD - MSDN: http://msdn.microsoft.com/en- us/library/hh213125
  • 37. • FIRST_VALUE - MSDN: http://msdn.microsoft.com/en- us/library/hh213018 • LAST_VALUE - MSDN: http://msdn.microsoft.com/en- us/library/hh231517
  • 38. • MSDN: http://msdn.microsoft.com/en- us/library/hh213573.aspx • Introduction to PERCENT_RANK(): http://blog.sqlauthority.com/2011/11/18/sql- server-introduction-to-percent_rank-analytic- functions-introduced-in-sql-server-2012/
  • 39. • MSDN: http://technet.microsoft.com/en- us/library/hh231078.aspx • Introduction to CUME_DIST: http://blog.sqlauthority.com/2011/11/08/sql- server-introduction-to-cume_dist-analytic- functions-introduced-in-sql-server-2012/
  • 40. • PERCENTILE_CONT - MSDN: http://msdn.microsoft.com/en- us/library/hh231473.aspx • Introduction to PERCENTILE_CONT: http://blog.sqlauthority.com/2011/11/20/sql- server-introduction-to-percentile_cont-analytic- functions-introduced-in-sql-server-2012/ • What exactly does PERCENTILE_CONT do? http://www.sqlskills.com/BLOGS/BOBB/post/Wh at-exactly-does-PERCENTILE_CONT-do- anyhow.aspx
  • 41. • PERCENTILE_DISC - MSDN: http://msdn.microsoft.com/en- us/library/hh231327 • Introduction to PERCENTILE_DISC: http://blog.sqlauthority.com/2011/11/22/sql- server-introduction-to-percentile_disc- analytic-functions-introduced-in-sql-server- 2012/
  • 42. • Difference between PARSE(), TRY_PARSE(), TRY_CONVERT(): http://blog.sqlauthority.com/2011/09/09/sql-server- denali-conversion-function-difference-between-parse- try_parse-try_convert/ • PARSE - MSDN: http://msdn.microsoft.com/en- us/library/hh213316.aspx • TRY_PARSE - MSDN: http://msdn.microsoft.com/en- us/library/hh974669 • TRY_CONVERT - MSDN: http://msdn.microsoft.com/en-us/library/hh230993
  • 44. • MSDN: http://msdn.microsoft.com/en- us/library/hh213019 • CHOOSE() – A Quick Introduction: http://blog.sqlauthority.com/2011/09/11/sql- server-denali-logical-function-choose-a-quick- introduction/
  • 45. • MSDN: http://msdn.microsoft.com/en- us/library/hh213020.aspx • EOMONTH() – A Quick Introduction: http://blog.sqlauthority.com/2011/09/20/sql- server-denali-date-and-time-functions- eomonth-a-quick-introduction/
  • 46. • A Quick Introduction: http://blog.sqlauthority.com/2011/09/19/sql- server-denali-date-and-time-functions- datefromparts-datetimefromparts- datetime2fromparts-timefromparts- smalldatetimefromparts- datetimeoffsetfromparts-a-quick-introduc/
  • 48. • MSDN: http://msdn.microsoft.com/en- us/library/hh213505.aspx • New SQL Server Function to Format Dates: http://www.mssqltips.com/sqlservertip/2655/ne w-sql-server-function-to-format- dates/?utm_source=dailynewsletter&utm_mediu m=email&utm_content=headline&utm_campaig n=2012427 • Custom Numeric Formats - http://msdn.microsoft.com/en- US/library/0c899ak8.aspx#SpecifierD

Editor's Notes

  • #4: Data Paging – OFFSET and FETCHAnalytic Window Functions – LAG, LEAD, FIRST_VALUE, LAST_VALUE, PERCENT_RANK, CUME_DIST, PERCENTILE_CONT, PERCENTILE_DISC Conversion Functions – PARSE, TRY_PARSE, TRY_CONVERTLogical Functions – IIF, CHOOSEDate/Time Functions – EOMONTH, FROMPARTSString Functions – CONCAT, FORMATError Handling - THROW