Converts the expression exp to the specified data type. Conversion can potentially cause truncation as shown in the examples below.
If this size parameter is omitted for the following data types, it defaults to a size of one: Char, Varchar, Binary, Varbinary, Nchar, and Nvarchar.
Valid data types are shown in the following table:
Data Type |
Description |
Bigint |
8-byte integer |
Integer |
4-byte integer |
Smallint |
2-byte integer |
Tinyint |
1-byte integer |
Char(size) |
Fixed length character string |
Varchar(size) |
Variable length character string |
Binary(size) |
Fixed length binary string |
Varbinary(size) |
Variable length binary string |
Date |
ODBC date |
Time |
ODBC time |
Timestamp |
ODBC date and time |
Double |
8-byte double |
Float |
4-byte real |
Bit |
bit |
Decimal(precision, scale) |
Decimal |
Numeric(precision, scale) |
Numeric |
Nchar(size) |
Unicode |
Nvarchar(size) |
Variable length Unicode |
Example:
CONVERT("123", integer)
Returns: 123
CONVERT(123, char(3))
Returns: "123"
CONVERT(123, char(2))
Returns: "12"
CONVERT(123, char)
Returns: "1"