PARSE() – SQL Server Function usage with Screenshot

Leave a comment (0) Go to comments

SQL Server Denali CTP3 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.

PARSE (), 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.

HOW to use PARSE() in SQL Server ?

PARSE() – SQL Server Function usage with Screenshot SQL Server Denali PARSE sql server 2011 2012 PARSE () How to use PARSE() in SQL Server

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)

Note :


  • PARSE() is used for converting string values to date/time and number types.
  • If the server does not have the CLR installed, this function will fail

For More Information, check BOL.

EOF - PARSE() – SQL Server Function usage with Screenshot, 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.