SQL 数据类型转换
代码
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
declare @Num money set @Num = 1234.56 select CONVERT(varchar(20), @Num, 0) -- 1234.56 select CONVERT(varchar(20), @Num, 1) -- 1,234.56 select CONVERT(varchar(20), @Num, 2) -- 1234.5600
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。