Académique Documents
Professionnel Documents
Culture Documents
Sequences
Data Paging
Analytic Window Functions
Conversion Functions
Logical Functions
Date/Time Functions
String Functions
Sequence
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.
sp_describe_first_result_set
Returns metadata for the
supplied SQL statement.
Useful for determining
column/database information for
a SQL statement or Stored
Procedure.
@browse_information_mode
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.
LAG
LEAD
FIRST_VALUE
LAST_VALUE
PERCENT_RANK
CUME_DIST
PERCENTILE_CONT
PERCENTILE_DISC
OVER
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
FIRST_VALUE and
LAST_VALUE
FIRST_VALUE: Retrieves the first
value in a partition.
LAST_VALUE: Retrieves the last
value in a partition.
PERCENT_RANK
Calculates a relative rank of a
row.
(RANK() 1) / (Total Rows 1)
CUME_DIST
Calculates the percentage of
values less than or equal to the
current value in the group.
COUNT(*) OVER (ORDER BY Col1)
/ Total Count
PERCENTILE_CONT
Calculates a percentile value
Will interpolate the appropriate
value
Can use to find the median
PERCENTILE_CONT(0.5)
PERCENTILE_DISC
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)
Conversion Functions
TRY_PARSE
Like PARSE but if an error occurs
returns a NULL.
Still uses the .Net CLR.
Conversion Functions
TRY_CONVERT
EOMONTH
Returns last date of a specified
month.
Can specify a month_to_add
argument to increment or
decrement result.
FROMPARTS Functions
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 )
CONCAT
Does what it saysconcatenates
strings together.
NULLs are automatically
converted to empty strings.
Can pass other data types for
concatenation.
FORMAT
Simplifies the string formatting
of dates and other data types.
No more memorizing numeric
predefined format values.
Returns a string.
Uses .Net CLR
THROW
Reduces the need to use
RAISERROR in TRY/CATCH blocks.
Can provide custom error
messages.
Always uses severity level 16.
Recommended Books
Thank You!!
Richie Rump
@Jorriss
jorriss@gmail.com
http://jorriss.net
http://dotnetmiami.com
Sequence
MSDN: http://msdn.microsoft.com/enus/library/ff878091.aspx
Sequence: Why they arent just for surrogate keys:
http://blog.infoadvisors.com/index.php/2012/02/16/
new-in-sql-server-2012-sequences-why-they-arentjust-for-surrogate-keys/
Sequence in 2012: http://www.sql-serverperformance.com/2011/sequence-sql-server-2011/
Create Sequence: http://www.dbadiaries.com/newt-sql-features-in-sql-server-2012-create-sequence/
sp_describe_first_result_set
MSDN:
http://msdn.microsoft.com/enus/library/ff878602.aspx
http://blog.sqlauthority.com/2012/
03/31/sql-serversp_describe_first_result_set-newsystem-stored-procedure-in-sqlserver-2012/
FIRST_VALUE, LAST_VALUE
FIRST_VALUE - MSDN:
http://msdn.microsoft.com/enus/library/hh213018
LAST_VALUE - MSDN:
http://msdn.microsoft.com/enus/library/hh231517
PERCENT_RANK
MSDN: http://msdn.microsoft.com/enus/library/hh213573.aspx
Introduction to PERCENT_RANK():
http://blog.sqlauthority.com/2011/11/
18/sql-server-introduction-topercent_rank-analytic-functionsintroduced-in-sql-server-2012/
CUME_DIST
MSDN:
http://technet.microsoft.com/enus/library/hh231078.aspx
Introduction to CUME_DIST:
http://blog.sqlauthority.com/2011/11/
08/sql-server-introduction-tocume_dist-analytic-functionsintroduced-in-sql-server-2012/
PERCENTILE_CONT
PERCENTILE_CONT - MSDN:
http://msdn.microsoft.com/enus/library/hh231473.aspx
Introduction to PERCENTILE_CONT:
http://blog.sqlauthority.com/2011/11/20/sqlserver-introduction-to-percentile_cont-analyticfunctions-introduced-in-sql-server-2012/
What exactly does PERCENTILE_CONT do?
http://www.sqlskills.com/BLOGS/BOBB/post/Whatexactly-does-PERCENTILE_CONT-do-anyhow.aspx
PERCENTILE_DISC
PERCENTILE_DISC - MSDN:
http://msdn.microsoft.com/enus/library/hh231327
Introduction to PERCENTILE_DISC:
http://blog.sqlauthority.com/2011/11/
22/sql-server-introduction-topercentile_disc-analytic-functionsintroduced-in-sql-server-2012/
Conversion Functions
Difference between PARSE(), TRY_PARSE(),
TRY_CONVERT():
http://blog.sqlauthority.com/2011/09/09/sql-serverdenali-conversion-function-difference-betweenparse-try_parse-try_convert/
PARSE - MSDN: http://msdn.microsoft.com/enus/library/hh213316.aspx
TRY_PARSE - MSDN: http://msdn.microsoft.com/enus/library/hh974669
TRY_CONVERT - MSDN:
http://msdn.microsoft.com/en-us/library/hh230993
IIF
MSDN: http://msdn.microsoft.com/enus/library/hh213574.aspx
CHOOSE
MSDN: http://msdn.microsoft.com/enus/library/hh213019
CHOOSE() A QuickIntroduction:
http://blog.sqlauthority.com/2011/09/
11/sql-server-denali-logical-functionchoose-a-quick-introduction/
EOMONTH
MSDN: http://msdn.microsoft.com/enus/library/hh213020.aspx
EOMONTH() A QuickIntroduction:
http://blog.sqlauthority.com/2011/09/
20/sql-server-denali-date-and-timefunctions-eomonth-a-quickintroduction/
FROMPARTS Functions
A Quick Introduction:
http://blog.sqlauthority.com/2011/09/
19/sql-server-denali-date-and-timefunctions-datefrompartsdatetimefrompartsdatetime2fromparts-timefrompartssmalldatetimefrompartsdatetimeoffsetfromparts-a-quickintroduc/
CONCAT
MSDN: http://msdn.microsoft.com/enus/library/hh231515.aspx
FORMAT
MSDN: http://msdn.microsoft.com/enus/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_medium=e
mail&utm_content=headline&utm_campaign=
2012427
Custom Numeric Formats http://msdn.microsoft.com/enUS/library/0c899ak8.aspx#SpecifierD
THROW
http://www.dbadiaries.com/new-t-sqlfeatures-in-sql-server-2012-throw/