使用样式 3 浮动到 varchar 在 sql 服务器 2016 中失败
Float to varchar with style 3 is failing in sql server 2016
我在 sql 服务器 2016 上执行以下查询时出现算术溢出错误。
"select convert(varchar(20), cast('0' as float), 3)"
相同的查询在 sql 服务器 2014 上运行良好。
CONVERT ( data_type [ ( length ) ] , 表达式 [ , 样式 ] )
The same query works fine
on sql server 2014.
sql 2014
风格
Other values are processed as 0.
A maximum of 6 digits. Use in scientific notation, when appropriate.
sql2016
风格
3 Always 17 digits. Use for lossless conversion. With this style, every distinct float or real value is guaranteed to convert to a
distinct character string.Applies to: Azure SQL Database, and starting in SQL Server 2016.
https://docs.microsoft.com/en-us/sql/t-sql/functions/cast-and-convert-transact-sql
您收到此错误原因 casting '0' to float of style 3 returning 23 charter value which is unable to convert to varchar of length 20 only
。
尝试类似的东西,
select convert(varchar(23), cast('0' as float), 3)
或者
select convert(varchar(max), cast('0' as float), 3)
我在 sql 服务器 2016 上执行以下查询时出现算术溢出错误。
"select convert(varchar(20), cast('0' as float), 3)"
相同的查询在 sql 服务器 2014 上运行良好。
CONVERT ( data_type [ ( length ) ] , 表达式 [ , 样式 ] )
The same query works fine on sql server 2014.
sql 2014
风格Other values are processed as 0. A maximum of 6 digits. Use in scientific notation, when appropriate.
sql2016
风格3 Always 17 digits. Use for lossless conversion. With this style, every distinct float or real value is guaranteed to convert to a distinct character string.Applies to: Azure SQL Database, and starting in SQL Server 2016.
https://docs.microsoft.com/en-us/sql/t-sql/functions/cast-and-convert-transact-sql
您收到此错误原因 casting '0' to float of style 3 returning 23 charter value which is unable to convert to varchar of length 20 only
。
尝试类似的东西,
select convert(varchar(23), cast('0' as float), 3)
或者
select convert(varchar(max), cast('0' as float), 3)