Wednesday 18 December 2013

PARSE () in SQL 2012

Introduction

PARSE () function is Introduced at MS SQL Server 2012. Here in this article we are trying to illustrate the PARSE () function.

Why the PARSE ()
The PARSE () function is used to convert staring value to Numeric or Date/Time format. Please remember that PARSE () function can convert only string value. If the string value cannot converted to Numeric or Date/Time format it will provide an Error.

What it needs
PARSE () function needs common language run time (CLR) to convert sting value to Numeric or Date/Time format. If the CLR is not installed the PARSE () returns an Error.

To install CLR use


Syntax of PARSE ()

PARSE ( string_value As data_type  [Using culture])

String_value - The expression which needs to be parsed.

Data_type - To which data type we are converting to.

CULTUre - To which culture, i.e., language such as gb-en, us-en. This is an optional parameter.

Culture part of the function is optional. Language like English, Japanese, Spanish, Danish, French etc. to be used by MS SQL Server to interpret data. If the culture is not specified the culture of the current session is used. The culture can be any of the .NET supported cultures.


Example of PARSE ()

SELECT PARSE('08-04-2013' AS DATETIME USING 'en-US') AS Date
Date
2013-08-04 00:00:000

SELECT PARSE('200.000' AS INT) AS ValueInt
ValueInt
200
SELECT PARSE('July 30, 2013' AS DATETIME)
AS ValueDT
ValueDT
2013-07-30 00:00:00.000.


Hope you like it.



Posted by: MR. JOYDEEP DAS

No comments:

Post a Comment