SQL Server Conversion Functions

SQL Server conversion functions are used to convert one data type to another data type. There are two built-in conversion function in sql server.

CAST and CONVERT

Syntaxes:

CAST(EXPRESS as datatype)
CONVERT(target datatype, source datatype)

SQL-Server-Insert1

Examples:
1. Convert salary as string.

SELECT empname+‘ earns ‘+ CAST(salary as varchar) from emp

SQL-Server-Conversion-functions

2. Convert joindate as string datatype.

select empname+‘ joined on ‘+CAST(joindate as varchar) from emp

3. Convert date type to varchar

select CONVERT(varchar,getdate())

4. Convert float to integer

select CONVERT(int, 23.456)
Output: 23

Powered by k2schools