In SQL Server, both the cast and CONVERT functions are available for type conversions, and their functions are the same.
It's just a different syntax.
Cast is generally easier to use, and the advantage of convert is that dates and values can be formatted.
CodeSelect CAST('123' as int)--123Select CONVERT(int,'123')--123Select CAST(123.4 as int)--123Select CONVERT(int,123.4)--123Select CAST('123.4' as int)Select CONVERT(int,'123.4')--Conversion failed when converting the varchar value ' 123.4 ' to data type int.Select CAST('123.4' as decimal)--123Select CONVERT(decimal,'123.4')--123Select CAST('123.4' as decimal(9,2))--123.40Select CONVERT(decimal(9,2),'123.4')--123.40Declare @Num MoneySet @Num = 1234.56Select CONVERT(varchar( -),@Num,0)--1234.56Select CONVERT(varchar( -),@Num,1)--1,234.56Select CONVERT(varchar( -),@Num,2)--1234.5600
The difference between cast and convert forced type conversions in SQL Server