将值从字符转换为货币时出错

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 query to group by day(按天分组的 SQL 查询)
What does SQL clause quot;GROUP BY 1quot; mean?(SQL 子句“GROUP BY 1是什么意思?意思是?)
Include missing months in Group By query(在 Group By 查询中包含缺失的月份)
sql group by versus distinct(sql group by 与不同)
How to return a incremental group number per group in SQL(如何在SQL中返回每个组的增量组号)
Count number of records returned by group by(统计分组返回的记录数)