代码改变世界

随笔分类 -  SQL Server

SQL Server 疑难杂症--转换科学计数法的数值字符串为decimal类型

2011-05-18 09:39 by Zork, 1870 阅读, 收藏,
摘要: 今天在操作数据库时,需要将字符串转换成Decimal类型。代码如下: select cast('0.12' as decimal(18,2)); select convert(decimal(18,2), '0.12'); 当需要将科学计数法的数字字符串转换成Decimal时,这2种写法都报错: Msg 8114, Level 16, State 5, Line 1 Error converting data type varchar to numeric. select cast('0.12e+006' as decimal(18,2)); s 阅读全文