SQL PARSE Function

The PARSE function converts a string value to the specified data type.

Use PARSE only for converting a string to datetime or a numeric value.

If the conversion fails, an error is returned.

Example

#

This example parses strings and converts these to other data types.

SELECT PARSE('1859' AS INT) AS '1859',
       PARSE('1859' AS DECIMAL(10, 2)) AS '1859.',
       PARSE('10/15/21' AS DATETIME) AS '10/15/21',
       PARSE('10/15/21 08:15 PM' AS DATETIME2) AS '10/15/21 08:15 PM'
Result:  1 record
1859 1859 10/15/21 10/15/21 08:15 PM
1859 1859.00 2021-10-15 00:00:00.000 2021-10-15 20:15:00.0000000

Syntax

Syntax of the PARSE function.

PARSE(string-value AS data-type [USING culture])

string-value -- a string value to convert.

data-type -- a data type the string-value will be converted to.

culture -- optional, the culture which the string-value is formatted.

These are the data types supported by PARSE.

Type
BIGINT
INT
SMALLINT
TINYINT
DECIMAL
NUMERIC
FLOAT
REAL
SMALLMONEY
MONEY
DATE
TIME
DATETIME
SMALLDATETIME
DATETIME2
DATETIMEOFFSET

These are the cultures supported by PARSE.

Culture Full name Language
en-US us_english English
de-DE Deutsch German
fr-FR Français French
ja-JP 日本語 Japanese
da-DK Dansk Danish
es-ES Español Spanish
it-IT Italiano Italian
nl-NL Nederlands Dutch
nn-NO Norsk Norwegian
pt-PT Português Portuguese
fi-FI Suomi Finnish
sv-SE Svenska Swedish
Cs-CZ čeština Czech
Hu-HU magyar Hungarian
Pl-PL polski Polish
Ro-RO română Romanian
hr-HR hrvatski Croatian
Sk-SK slovenčina Slovak
Sl-SI slovenski Slovenian
El-GR ελληνικά Greek
bg-BG български Bulgarian
Ru-RU русский Russian
Tr-TR Türkçe Turkish
en-GB British British English
Et-EE eesti Estonian
lv-LV latviešu Latvian
lt-LT lietuvių Lithuanian
pt-BR Português (Brasil) Brazilian
zh-TW 繁體中文 Traditional Chinese
Ko-KR 한국어 Korean
zh-CN 简体中文 Simplified Chinese
ar-SA Arabic Arabic
Th-TH ไทย Thai

You may also like



Guides


vsn 3.1