Error in converting value from char to money(将值从字符转换为货币时出错)
问题描述
我有一个表 tableA,其中包含数据类型 varchar 的列 [Amount].
I have a table tableA that contains a column [Amount] of datatype varchar.
它具有如下值:
47980.89
333652.61
332388.84
374664.48
368715.26
371689.33
371689.33
368715.26
374664.48
现在,当我运行查询时,它运行成功,但每次都给出不同的输出
Now when I run my query, it runs successfully but gives different output each time
SELECT
sum(convert(float, Amount))
FROM tableA
当我尝试其他语句时,出现错误
and when I try this other statement, I get an error
无法将字符值转换为货币.char 值的语法不正确.
Cannot convert a char value to money. The char value has incorrect syntax.
代码:
SELECT
sum(convert(money, Amount))
FROM tableA
我想要列的总和 [Amount]
推荐答案
应该这样做:
select Sum(isnull(cast(amount as float),0)) from #t
或者你需要它是货币数据类型
or you need it to be money data-type
select Sum(isnull(cast(amount as money),0)) from #t
这篇关于将值从字符转换为货币时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:将值从字符转换为货币时出错
基础教程推荐
- 二进制文件到 SQL 数据库 Apache Camel 2021-01-01
- 在 MySQL 中:如何将表名作为存储过程和/或函数参数传递? 2021-01-01
- 如何根据该 XML 中的值更新 SQL 中的 XML 2021-01-01
- mysql选择动态行值作为列名,另一列作为值 2021-01-01
- 什么是 orradiag_<user>文件夹? 2022-01-01
- 表 './mysql/proc' 被标记为崩溃,应该修复 2022-01-01
- oracle区分大小写的原因? 2021-01-01
- 在多列上分布任意行 2021-01-01
- 如何在 SQL 中将 Float 转换为 Varchar 2021-01-01
- MySQL 中的类型:BigInt(20) 与 Int(20) 2021-01-01
