将值从字符转换为货币时出错 [英] Error in converting value from char to money

查看:26
本文介绍了将值从字符转换为货币时出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个表 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

这篇关于将值从字符转换为货币时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆