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.
Select CAST (' 123 ' as int)--123
Select CONVERT (int, ' 123 ')--123
Select CAST (123.4 as int)--123
Select CONVERT (int, 123.4)--123
Select 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)--123
Select CONVERT (Decimal, ' 123.4 ')--123
Select CAST (' 123.4 ' as Decimal (9,2))--123.40
Select CONVERT (Decimal (9,2), ' 123.4 ')--123.40
//Use Real to match. 55 Such data
Select CONVERT (Real, '. ")--0.55
DECLARE @Num Money
Set @Num = 1234.56
Select CONVERT (varchar (0), @Num,)--1234.56
Select CONVERT (varchar), @Num, 1)--1,234.56
Select CONVERT (varchar (2), @Num,)--1234.5600
Forced type conversions in SQL Server cast and convert