0% found this document useful (0 votes)
33 views

Lectura 1 - PARSE (Transact-SQL) - SQL Server - Microsoft Docs

The PARSE function in Transact-SQL returns the result of an expression translated to a requested data type. It takes a string value and data type as arguments, and optionally a culture. It parses the string into the specified data type based on number, date/time, or other formatting rules associated with the data type and culture. Common uses are to convert strings to date/time or number types.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
33 views

Lectura 1 - PARSE (Transact-SQL) - SQL Server - Microsoft Docs

The PARSE function in Transact-SQL returns the result of an expression translated to a requested data type. It takes a string value and data type as arguments, and optionally a culture. It parses the string into the specified data type based on number, date/time, or other formatting rules associated with the data type and culture. Common uses are to convert strings to date/time or number types.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

4/7/2020 PARSE (Transact-SQL) - SQL Server | Microsoft Docs

PARSE (Transact-SQL)
07/05/2017 • 3 minutes to read • +4

In this article
Syntax
Arguments
Return Types
Remarks
Examples

Applies to: SQL Server (all supported versions) Azure SQL Database

Returns the result of an expression, translated to the requested data type in SQL Server.

Transact-SQL Syntax Conventions

Syntax
= Copy

PARSE ( string_value AS data_type [ USING culture ] )

Arguments
string_value
nvarchar(4000) value representing the formatted value to parse into the specified data
type.

string_value must be a valid representation of the requested data type, or PARSE raises
an error.

data_type
Literal value representing the data type requested for the result.

culture
Optional string that identifies the culture in which string_value is formatted.

If the culture argument is not provided, then the language of the current session is
used. This language is set either implicitly, or explicitly by using the SET LANGUAGE

https://docs.microsoft.com/en-us/sql/t-sql/functions/parse-transact-sql?view=sql-server-ver15 1/6
4/7/2020 PARSE (Transact-SQL) - SQL Server | Microsoft Docs

statement. culture accepts any culture supported by the .NET Framework; it is not
limited to the languages explicitly supported by SQL Server. If the culture argument is
not valid, PARSE raises an error.

Return Types
Returns the result of the expression, translated to the requested data type.

Remarks
Null values passed as arguments to PARSE are treated in two ways:

1. If a null constant is passed, an error is raised. A null value cannot be parsed into a
different data type in a culturally aware manner.

2. If a parameter with a null value is passed at run time, then a null is returned, to
avoid canceling the whole batch.

Use PARSE only for converting from string to date/time and number types. For general
type conversions, continue to use CAST or CONVERT. Keep in mind that there is a
certain performance overhead in parsing the string value.

PARSE relies on the presence of the .NET Framework Common Language Runtime (CLR).

This function will not be remoted since it depends on the presence of the CLR.
Remoting a function that requires the CLR would cause an error on the remote server.

More information about the data_type parameter

The values for the data_type parameter are restricted to the types shown in the
following table, together with styles. The style information is provided to help
determine what types of patterns are allowed. For more information on styles, see the
.NET Framework documentation for the System.Globalization.NumberStyles and
DateTimeStyles enumerations.

Category Type .NET Styles used


Framework
type

Numeric bigint Int64 NumberStyles.Number

Numeric int Int32 NumberStyles.Number

Numeric smallint Int16 NumberStyles.Number

https://docs.microsoft.com/en-us/sql/t-sql/functions/parse-transact-sql?view=sql-server-ver15 2/6
4/7/2020 PARSE (Transact-SQL) - SQL Server | Microsoft Docs

Category Type .NET Styles used


Framework
type

Numeric tinyint Byte NumberStyles.Number

Numeric decimal Decimal NumberStyles.Number

Numeric numeric Decimal NumberStyles.Number

Numeric float Double NumberStyles.Float

Numeric real Single NumberStyles.Float

Numeric smallmoney Decimal NumberStyles.Currency

Numeric money Decimal NumberStyles.Currency

Date and date DateTime DateTimeStyles.AllowWhiteSpaces |


Time DateTimeStyles.AssumeUniversal

Date and time TimeSpan DateTimeStyles.AllowWhiteSpaces |


Time DateTimeStyles.AssumeUniversal

Date and datetime DateTime DateTimeStyles.AllowWhiteSpaces |


Time DateTimeStyles.AssumeUniversal

Date and smalldatetime DateTime DateTimeStyles.AllowWhiteSpaces |


Time DateTimeStyles.AssumeUniversal

Date and datetime2 DateTime DateTimeStyles.AllowWhiteSpaces |


Time DateTimeStyles.AssumeUniversal

Date and datetimeoffset DateTimeOffset DateTimeStyles.AllowWhiteSpaces |


Time DateTimeStyles.AssumeUniversal

More information about the culture parameter

The following table shows the mappings from SQL Server languages to .NET Framework
cultures.

Full name Alias LCID Specific culture

us_english English 1033 en-US

https://docs.microsoft.com/en-us/sql/t-sql/functions/parse-transact-sql?view=sql-server-ver15 3/6
4/7/2020 PARSE (Transact-SQL) - SQL Server | Microsoft Docs

Full name Alias LCID Specific culture

Deutsch German 1031 de-DE

Français French 1036 fr-FR

日本語 Japanese 1041 ja-JP

Dansk Danish 1030 da-DK

Español Spanish 3082 es-ES

Italiano Italian 1040 it-IT

Nederlands Dutch 1043 nl-NL

Norsk Norwegian 2068 nn-NO

Português Portuguese 2070 pt-PT

Suomi Finnish 1035 fi-FI

Svenska Swedish 1053 sv-SE

čeština Czech 1029 Cs-CZ

magyar Hungarian 1038 Hu-HU

polski Polish 1045 Pl-PL

română Romanian 1048 Ro-RO

hrvatski Croatian 1050 hr-HR

slovenčina Slovak 1051 Sk-SK

slovenski Slovenian 1060 Sl-SI

ελληνικά Greek 1032 El-GR

български Bulgarian 1026 bg-BG

русский Russian 1049 Ru-RU

https://docs.microsoft.com/en-us/sql/t-sql/functions/parse-transact-sql?view=sql-server-ver15 4/6
4/7/2020 PARSE (Transact-SQL) - SQL Server | Microsoft Docs

Full name Alias LCID Specific culture

Türkçe Turkish 1055 Tr-TR

British British English 2057 en-GB

eesti Estonian 1061 Et-EE

latviešu Latvian 1062 lv-LV

lietuvių Lithuanian 1063 lt-LT

Português (Brasil) Brazilian 1046 pt-BR

繁體中文 Traditional Chinese 1028 zh-TW

한국어 Korean 1042 Ko-KR

简体中文 Simplified Chinese 2052 zh-CN

Arabic Arabic 1025 ar-SA

ไทย Thai 1054 Th-TH

Examples

A. PARSE into datetime2

= Copy

SELECT PARSE('Monday, 13 December 2010' AS datetime2 USING 'en-US') AS


Result;

Here is the result set.

= Copy

Result
---------------
2010-12-13 00:00:00.0000000

(1 row(s) affected)

https://docs.microsoft.com/en-us/sql/t-sql/functions/parse-transact-sql?view=sql-server-ver15 5/6
4/7/2020 PARSE (Transact-SQL) - SQL Server | Microsoft Docs

B. PARSE with currency symbol

= Copy

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

Here is the result set.

= Copy

Result
---------------
345.98

(1 row(s) affected)

C. PARSE with implicit setting of language

= Copy

-- The English language is mapped to en-US specific culture


SET LANGUAGE 'English';
SELECT PARSE('12/16/2010' AS datetime2) AS Result;

Here is the result set.

= Copy

Result
---------------
2010-12-16 00:00:00.0000000

(1 row(s) affected)

Is this page helpful?

 Yes  No

https://docs.microsoft.com/en-us/sql/t-sql/functions/parse-transact-sql?view=sql-server-ver15 6/6

You might also like