Skip to main content

CONVERT( ) Function

Definition The CONVERT() function converts a value (of any type) into a specified datatype.   Syntax CONVERT(data_type(length), expression, style) where  data_type is required and is the datatype to c

Updated over 2 weeks ago

Definition

The CONVERT() function converts a value (of any type) into a specified datatype.

Syntax

CONVERT(data_type(length), expression, style)

where

data_type is required and is the datatype to convert expression to. Can be one of the following: bigint, int, smallint, tinyint, bit, decimal, numeric, money, smallmoney, float, real, datetime, smalldatetime, char, varchar, text, nchar, nvarchar, ntext, binary, varbinary, or image.

(length) is optional and is the length of the resulting data type (for char, varchar, nchar, nvarchar, binary and varbinary).

expression is required and is the value to convert to another data type.

style is optional and is the format used to convert between data types, such as a date or string format. Refer to https://www.w3schools.com/sql/func_sqlserver_convert.asp to see the values available for: converting datetime to character, converting float to real and converting money to character.

Example(s)

See how CONVERT() can be used to:

Did this answer your question?