Quantcast
Channel: functions – SQL Server Rider
Viewing all articles
Browse latest Browse all 13

SQL SERVER 2012 – Convert an Expression to Specific Data Type using PARSE Conversion Function

$
0
0

Parse : This conversion function is used to compute the expression and return the output to the desired data type. But, this function is in SQL Server 2012 and onwards.

Parse function suitable for data and numeric data and it requires CLR because it is a .NET function. So, as usual there will be some performance impact if we use in large mission critical application. We still have cast and convert functions for type casting.

This function requires a valid data and appropriate convertible data type. Otherwise, parse function raise error.

I think the best feature is this function is language or culture option. We can specify the culture type in the conversion. So, the output reflects the given culture with converted data type.

Usage

PARSE ( string_value AS data_type [ USING culture ] )

string_value : It is nvarchar(4000) storage.

data_type : These are the valid data types

pic1culture : Optional string that identifies the culture in which string_value is formatted. Please refer this blog post for languages in SQL Server.

Example

1. Parsing currency of different region.

SELECT PARSE(‘€345,98′ AS money USING ‘de-DE’) AS Result;

Output

pic12. Parsing date of the given language or locale

SELECT PARSE(’13 August 2013′ AS datetime2 USING ‘en-us’) AS Result;

Output

pic2



Viewing all articles
Browse latest Browse all 13

Trending Articles