In Transact-SQL, two levels of data type conversions are possible:
There are two categories of data type conversions:
SQL Server automatically converts the data from one data type to another. For example, if a smallint is compared to an int, the smallint is implicitly converted to int before the comparison proceeds.
The CAST and CONVERT functions convert a value (a local variable, a column, or another expression) from one data type to another. For example, the following CAST function converts the numeric value of $157.27 into a character string of ‘$157.27’:
CAST ( $157.27 AS VARCHAR(10) )
CAST is based on the SQL-92 standard and is preferred over CONVERT.
When converting from the data type of one SQL Server object to another, some implicit and explicit data type conversions are not supported. For example, an nchar value cannot be converted to an image value at all. An nchar can only be converted to binary using explicit conversion, an implicit conversion to binary is not supported. An nchar can be either explicitly or implicitly converted to nvarchar. For more information about supported conversions between SQL Server objects, see CAST and CONVERT.
When converting between an application variable and a SQL Server result set column, return code, parameter, or parameter marker, the supported data type conversions are defined by the database application programming interface (API).