Transform an expression into an integer data type.
SELECT CONVERT(int, 25.65); |
The CONVERT() function in SQL Server converts a value of any type into a specified data type, offering flexibility in data manipulation and formatting.
Tip: Consider using the CAST() function for similar data type conversions.
CONVERT(data_type(length), expression, style) |
Parameter |
Description |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
datatype |
Mandatory. Specifies the target data type to which the expression will be converted. Options include: bigint, int, smallint, tinyint, bit, decimal, numeric, money, smallmoney, float, real, datetime, smalldatetime, char, varchar, text, nchar, nvarchar, ntext, binary, varbinary, or image. |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
(length) |
Optional. Specifies the length or size of the resulting data type, applicable to conversions involving char, varchar, nchar, nvarchar, binary, and varbinary. |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
expression |
Mandatory. The value that is to be converted to a different data type. |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
style |
Optional. The format used for conversions between data types, such as when converting datetime values to character strings.
Transforming a floating-point value into a real number.
Converting a monetary value to a character string.
|
Works in: |
SQL Server (from 2008 onward), Azure SQL Database, Azure SQL Data Warehouse, and Parallel Data Warehouse |
Change the data type of an expression to varchar.
SELECT CONVERT(varchar, 25.65); |
Transform an expression into a datetime data type.
SELECT CONVERT(datetime, ‘2017-08-25’); |
Change the data type of an expression to varchar.
SELECT CONVERT(varchar, ‘2017-08-25’, 101); |