varchar 列中的数据总和 [英] Sum of data in varchar column

查看:36
本文介绍了varchar 列中的数据总和的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我必须对 varchar 列 (SCENARIO1) 中的元素求和并包含 (1,920, 270.00, 0, NULL) 之类的数据,但是当我尝试将数据转换为 int 或 decimal 时,出现此错误:将值4582014,00"转换为int类型时命令错误"

i have to sum element in a column(SCENARIO1) that is varchar and contain data like (1,920, 270.00, 0, NULL) but when i try to convert data into int or decimal i get this error : "he command is wrong when converting value "4582014,00" to int type"

这是我的要求:

select sum( convert( int, SCENARIO1) )
from Mnt_Scenario_Exercice where code_pere='00000000'

请帮忙

推荐答案

试试这个

select sum(cast(replace(SCENARIO1, ',', '.') as decimal(29, 10)))
from Mnt_Scenario_Exercice
where code_pere = '00000000';

如果您无法将 '4582014,00' 转换为十进制,则您的服务器上可能有不同的小数分隔符.你可以看看它是什么或者只是试试 '.'

If you couldn't convert your '4582014,00' into decimal, there's a chance you have different decimal separator on your server. You could look what it is or just try '.'

这篇关于varchar 列中的数据总和的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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