The difference between coercion cast and convert in SQL Server
In SQL Server, both the cast and CONVERT functions are available for type conversions, and their functions are the same.
Just different grammar.
Cast is generally easier to use, and the advantage of convert is that you can format dates and values.
Select CAST (' 123 ' as int)-- 123
Select CONVERT (int, ' 123 ')--123
Select CAST (123.4 as int)- -123
SE Lect convert (int, 123.4)--123
Select CAST (' 123.4 ' as int)
select CONVERT (int, ' 123.4 ')-
-conversion Faile D 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
declare @Num money
Set @Num = 1234.56
s Elect convert (varchar, @Num, 0)--1234.56
Select CONVERT (varchar, @Num, 1)--1,234.56
Select CONVERT ( varchar, @Num, 2)--1234.5600
Thank you for reading, I hope to help you, thank you for your support for this site!