posted 6/11/2012 by ChrisAlbrektson - Views: [1413]
SQL Server 2012 TSQL Conversion Functions Part 4
In this forth blog post we will cover the new Conversion functions available in SQL 2012. This is the second to last topic of this miniseries of blog posts covering the new TSQL function in SQL server 2012.
The first function we will be looking at today is the Parse function.
Syntax, PARSE ( string_value AS data_type [ USING culture ] )
Examples:
SELECT PARSE('Wednesday, 04 July 2012' AS datetime USING 'en-US') AS Result
The second function we will be looking at today is the Try_Parse function.
Syntax, TRY_PARSE ( string_value AS data_type [ USING culture ] )
select TRY_PARSE('07/04/2012' AS int) as result
select TRY_PARSE('07/04/2012' AS datetime2) as result
The third function we will be looking at today is the Try_Convert function.
Syntax, TRY_CONVERT ( data_type [ ( length ) ], expression [, style ] )
SELECT TRY_CONVERT(datetime2, '07/04/2012') AS result
For more info on each of these functions please visit the MSDN links below. These have been simple examples just too introduce these new functions to you. I encourage you to experiment with these new functions and stayed tuned for my next blog for part 5.
Parse
Try_Parse
Try_Convert