14 New T-SQL Functions By Sam Nasr, MCAD, MCTS. MVP Nasr Information Systems February 8, 2014.

Slides:



Advertisements
Similar presentations
Introduction to HTML5 By Sam Nasr, MCAD, MCT, MCTS, MVP Nasr Information Systems October 22, 2013.
Advertisements

Moving from Access Databases to a Visual Studio/SQL Server Solutions Andrew Couch UK Access User Group asc associates
CSCI 6962: Server-side Design and Programming Input Validation and Error Handling.
By Sam Nasr Nasr Information Systems May 14, 2013.
Databases Lab 5 Further Select Statements. Functions in SQL There are many types of functions provided. The ones that are used most are: –Date and Time.
Working with Data Types February 7, 2015 John Deardurff Website:
Rationale Aspiring Database Developers should be able to efficiently query and maintain databases. This module will help students learn the Structured.
An Introduction To CLR Integration in SQL Server 2005 (Yukon) Dr Greg Low.
Introduction to Databases Chapter 6: Understanding the SQL Language.
Sofia, Bulgaria | 9-10 October TSQL Enhancements in SQL Server 2005 Stephen Forte CTO, Corzen Inc Microsoft Regional Director NY/NJ (USA) Stephen Forte.
SQL Server 2008 for Developers John
Java Primitives The Smallest Building Blocks of the Language (corresponds with Chapter 2)
Said Salomon Unitrin Direct Insurance T-SQL Date and Time Functions Said Salomon.
BARBARIN DAVID SQL Server Senior Consultant Pragmantic SQL Server Denali : New development features.
TSQL Improvements & Data Types SQL Server 2008 TSQL Improvements & Data Types Presented by Tarek Ghazali IT Technical Specialist Microsoft SQL Server MVP,
Chapter 3 Processing and Interactive Input. 2 Assignment  The general syntax for an assignment statement is variable = operand; The operand to the right.
CNG 140 C Programming Lecture Notes 2 Processing and Interactive Input Spring 2007.
WHAT’S NEW IN SQL SERVER 2008: T-SQL Martin Bell SQL Server MVP.
What’s New In Denali - TSQL David Ballantyne. Who am I Kent.Net/SqlServer.
BIS Database Systems School of Management, Business Information Systems, Assumption University A.Thanop Somprasong Chapter # 8 Advanced SQL.
Instructor: Craig Duckett Lecture 08: Thursday, October 22 nd, 2015 Patterns, Order of Evaluation, Concatenation, Substrings, Trim, Position 1 BIT275:
EXPRESSION Transformation. Introduction ►Transformations help to transform the source data according to the requirements of target system and it ensures.
IFS Intro to Data Management Chapter 5 Getting More Than Simple Columns.
SQL for SQL Server, C13© 2002, Mike Murach & Associates, Inc. Slide 1.
SQL ORACLE 1. Data Type 2 3 VARCHAR2(size [BYTE | CHAR]) Variable-length character string having maximum length size bytes or characters. Maximum size.
03 | SQL Server Data Types Brian Alderman | MCT, CEO / Founder of MicroTechPoint Tobias Ternstrom | Microsoft SQL Server Program Manager.
Data types  CHAR (size): This data type is used to store character strings values of fixed length. The size in brackets determines the number of characters.
LISTS and TUPLES. Topics Sequences Introduction to Lists List Slicing Finding Items in Lists with the in Operator List Methods and Useful Built-in Functions.
SQL server Section 2&3. What are Data Types Character Data Types Number Data Types Date and Time Data Types CAST and CONVERT functions TRY_PARSE and TRY_CONVERT.
Module 9: Using Advanced Techniques. Considerations for Querying Data Working with Data Types Cursors and Set-Based Queries Dynamic SQL Maintaining Query.
14 New T-SQL Functions By Sam Nasr, MCAD, MCT, MCTS NIS August 18, 2012.
What is your Character Data Type? March 5, 2016 John Deardurff Website:
BI Development By Sam Nasr, MCAD, MCT, MCTS Nasr Information Systems February 5, 2011.
14 New T-SQL Functions By Sam Nasr, MCAD, MCT, MCTS NIS
Creating Database Objects
FileTables Sam Nasr, MCAD, MCTS, MVP NIS Technologies
Programming with FileStream Object
More SQL: Complex Queries,
Temporal Tables Sam Nasr, MCSA, MVP NIS Technologies July 22, 2017
In this session, you will learn to:
Execution Planning for Success
Building Applications with LUIS
FileTables By Sam Nasr, MCAD, MCT, MCTS NIS October 6, 2012
Using FileTables Sam Nasr, MCSA, MCT, MVP NIS Technologies
Ouch! Our Data Type Choices Did THAT?
Using FileTables Sam Nasr, MCAD, MCTS, MVP NIS Technologies
SQL Server 2016 JSON Support FOR Data Warehousing
Microsoft SQL Server Managing Database Applications
SQL Server 2016 Security Features
Using Built-In Functions
14 T-SQL Functions You May Not Know
(SQL) Aggregating Data Using Group Functions
Proper DataType Usage = Guaranteed Better Performance and Accuracy
What is your Character Data Type?
SQL Server 2008 By Sam Nasr March 25, 2008.
Working with Data Types
NULLs and Other SQL Gotchas
Chapter # 7 Introduction to Structured Query Language (SQL) Part II.
Aggregating Data Using Group Functions
Data Types Do Matter Start local instance of SQL Start ZoomIt
NULLs and Other SQL Gotchas
14 T-SQL Functions You May Not Know
Integrating REST API and SQL Server JSON Functions
Data Time Travel with Temporal Tables
Trainer: Bach Ngoc Toan– TEDU Website:
Creating Database Objects
Using FileTables Sam Nasr, MCSA NIS Technologies August 3, 2019.
Data Time Travel with Temporal Tables
Working with SQL Server 2016 Data Types
Data Time Travel with Temporal Tables
Presentation transcript:

14 New T-SQL Functions By Sam Nasr, MCAD, MCTS. MVP Nasr Information Systems February 8, 2014

Introduction Sam Nasr Software developer since 1995 Founder - Nasr Information Systems MCAD, MCT, MCTS(WSS/MOSS) President - Cleveland C#/VB.Net User Group President - Cleveland WPF User Group President -.Net Study Group INETA Mentor for Ohio INETA Community Champ (2010, 2013) Author for Visual Studio Magazine

Housekeeping Restrooms Forum for learning Feel free to ask questions Cell Phones on mute please

What is your background?.Net Developer T-Sql Developer DBA Hobbyist/other role

System Requirements (Recommended) 6GB HD min (feature dependant) 4GB RAM min (increased per DB size) 2.0 GHz CPU x86 or x64 Vista, Win 7, Win Server 2008 NTFS recommended (FAT32 supported).Net 3.5 SP1/4.0 Note: All requirements are version dependant. See MSDN for more installation details.

14 New T-SQL Functions Conversion functions 1. PARSE 2. TRY_CONVERT 3. TRY_PARSE Date and time functions 4. DATEFROMPARTS 5. DATETIME2FROMPARTS 6. DATETIMEFROMPARTS 7. DATETIMEOFFSETFROMPARTS 8. EOMONTH 9. SMALLDATETIMEFROMPARTS 10. TIMEFROMPARTS Logical functions 11. CHOOSE 12. IIF String functions 13. CONCAT 14. FORMAT

14 New T-SQL Functions Conversion functions 1. PARSE 2. TRY_CONVERT 3. TRY_PARSE Date and time functions 4. DATEFROMPARTS 5. DATETIME2FROMPARTS 6. DATETIMEFROMPARTS 7. DATETIMEOFFSETFROMPARTS 8. EOMONTH 9. SMALLDATETIMEFROMPARTS 10. TIMEFROMPARTS Logical functions 11. CHOOSE 12. IIF String functions 13. CONCAT 14. FORMAT

Parse PARSE ( string_value AS data_type [ USING culture ] ) Transforms a string expression to date/time or number type. Optional clause [Using Culture] Requires.Net CLR (cannot be remoted) Use only for converting strings to datetime and numbers For general type conversions, continue to use CAST or CONVERT Transform Patterns are limited by styles in.Net CLR

TRY_CONVERT TRY_CONVERT ( data_type [ ( length ) ], expression [, style ] ) Converts an expression to a specified type Returns null if not successful. Returns error when cast is explicitly not permitted Allows for optional use of styles.

TRY_PARSE TRY_PARSE ( string_value AS data_type [ USING culture ] ) Similar to PARSE Function Returns null if value is not a valid representation of data_type PARSE Function raises an error.

Demo Conversion Functions

14 New T-SQL Functions Conversion functions 1. PARSE 2. TRY_CONVERT 3. TRY_PARSE Date and time functions 4. DATEFROMPARTS 5. DATETIME2FROMPARTS 6. DATETIMEFROMPARTS 7. DATETIMEOFFSETFROMPARTS 8. EOMONTH 9. SMALLDATETIMEFROMPARTS 10. TIMEFROMPARTS Logical functions 11. CHOOSE 12. IIF String functions 13. CONCAT 14. FORMAT

DATEFROMPARTS DATEFROMPARTS ( year, month, day ) Returns a date value for separate integer values of year, month, and day. It cannot be executed remotely on an earlier version of SQL Server. All values must be valid date values

DATETIMEFROMPARTS DATETIMEFROMPARTS ( year, month, day, hour, minute, seconds, milliseconds ) DATETIMEFROMPARTS returns a fully initialized datetime value. If the arguments are not valid, then an error is raised. If required arguments are null, then a null is returned. Cannot be executed remotely on an earlier version of SQL Server.

DATETIME2FROMPARTS DATETIME2FROMPARTS ( year, month, day, hour, minute, seconds, fractions, precision ) Returns a datetime2 value for separate integer values of year, month, day, hour, minutes, seconds, fractions, precision All values must be valid date/time values “Precision” must accommodate “fractions” value Max precision is 7

DATETIMEOFFSETFROMPARTS DATETIMEOFFSETFROMPARTS ( year, month, day, hour, minute, seconds, fractions, hour_offset, minute_offset, precision ) Returns a datetimeoffset value for separate integer values of year, month, day, hour, minutes, seconds, fractions, precision, and time offset. Offset arguments represent the time zone offset. If required arguments are null, a null is returned. If “Precision” is null, an error is raised.

EOMONTH EOMONTH ( start_date [, month_to_add ] ) Returns End-Of-Month date for the month of specified date. Optional month_to_add integer expression for number of months to add to start_date. month_to_add is added to start_date and returns the last day of the month for the resulting date. If this addition overflows the valid range of dates, then an error is raised.

SMALLDATETIMEFROMPARTS SMALLDATETIMEFROMPARTS ( year, month, day, hour, minute ) Similar to DATETIMEFROMPARTS Returns a smalldatetime value. If the arguments are not valid, then an error is thrown. If required arguments are null, then null is returned. Cannot be executed remotely on an earlier version of SQL Server.

TIMEFROMPARTS TIMEFROMPARTS ( hour, minute, seconds, fractions, precision ) Returns a fully initialized time value. If the arguments are invalid, then an error is raised. If any of the parameters are null, null is returned. If the precision argument is null, then an error is raised.

Demo Date and Time Functions

14 New T-SQL Functions Conversion functions 1. PARSE 2. TRY_CONVERT 3. TRY_PARSE Date and time functions 4. DATEFROMPARTS 5. DATETIME2FROMPARTS 6. DATETIMEFROMPARTS 7. DATETIMEOFFSETFROMPARTS 8. EOMONTH 9. SMALLDATETIMEFROMPARTS 10. TIMEFROMPARTS Logical functions 11. CHOOSE 12. IIF String functions 13. CONCAT 14. FORMAT

CHOOSE CHOOSE ( index, val_1, val_2 [, val_n ] ) Returns the item at the specified index from a list of values. Note: Index is 1-based Returns the data type with the highest precedence from the set of types passed to the function Note: T-SQL has 30 types UDT (Highest) …. Binary (Lowest)

IIF IIF ( boolean_expression, true_value, false_value ) Returns the respective value, depending on evaluation of Boolean expression. Returns the data type with the highest precedence from the types in true_value and false_value. IIF is translated into a CASE statement. IIF & CASE statements can be nested only up to 10 max IIF is remoted as a semantically equivalent CASE statement.

Demo Logical Functions

14 New T-SQL Functions Conversion functions 1. PARSE 2. TRY_CONVERT 3. TRY_PARSE Date and time functions 4. DATEFROMPARTS 5. DATETIME2FROMPARTS 6. DATETIMEFROMPARTS 7. DATETIMEOFFSETFROMPARTS 8. EOMONTH 9. SMALLDATETIMEFROMPARTS 10. TIMEFROMPARTS Logical functions 11. CHOOSE 12. IIF String functions 13. CONCAT 14. FORMAT

CONCAT CONCAT ( string_value1, string_value2 [, string_valueN ] ) Returns a string that is the result of concatenating two or more string values. Requires 2 – 254 arguments or an error is raised. Arguments are implicitly converted to string types Null values are implicitly converted to an empty string If all the arguments are null, an empty string of type varchar(1) is returned.

FORMAT FORMAT ( value, format [, culture ] ) Returns a value formatted with the specified format Optional culture parameter Format must contain a valid.NET Framework format string Composite formatting is not supported: Format("Name = {0},

Demo String Functions

Recap Conversion functions 1. PARSE 2. TRY_CONVERT 3. TRY_PARSE Date and time functions 4. DATEFROMPARTS 5. DATETIME2FROMPARTS 6. DATETIMEFROMPARTS 7. DATETIMEOFFSETFROMPARTS 8. EOMONTH 9. SMALLDATETIMEFROMPARTS 10. TIMEFROMPARTS Logical functions 11. CHOOSE 12. IIF String functions 13. CONCAT 14. FORMAT

Resources 4-New-TSQL-Functions.aspx?Page=1 4-New-TSQL-Functions.aspx?Page=1

Contact Info Thank you for attending!