PARSE in sql

Leave a comment (0) Go to comments

SQL Server 2012 has introduces a new function PARSE() to translate the result of an expression to specified data type that too is specified language.

PARSE() returns the result of an expression, translated to specified data type if the translation is possible, otherwise, it raises an error.

SQL PARSE () funtion, expects three parameters,

  1. string_value – string value to parse into the specified data type.
  2. data_type – return data type, numeric or datetime type
  3. culture - a language (English, Japanese, Spanish, Danish, French etc.) which will used by SQL Server to interpret data.

Quick example :

SELECT PARSE (’2012-01-06′ as DATE) as [2012-01-06]
SELECT PARSE (’2012-01-06′ as DATE) as [Exception]

HOW to use PARSE() in SQL Server ?

PARSE in sql

another example

select PARSE('20.20' AS INT) AS Result

-- RETRUNS Error as 10.2 in not integer value, this has decimals
-- Msg 9819, Level 16, State 1, Line 1
-- Error converting string value '10.20' into data type int using culture ”.

SELECT PARSE('Monday, 21 July 2011' AS datetime2, 'en-US') AS Result

-- RETUNRS 

Result
---------------
2011-07-21 00:00:00.0000000

(1 row(s) affected)

sql parse, parse in sql, parse sql, parse sql server, sql server parse

EOF - PARSE in sql, SQL Server 2012 , 2008 R2 , 2008 , 2005 , 2000

Leave a Reply

Your email address will not be published. Required fields are marked *


*


You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Notify me of followup comments via e-mail. You can also subscribe without commenting.