SQL Server 2005:将varchar值“0.00”转换为数据类型int时,转换失败
将此行添加到我的查询中时:SQL Server 2005:将varchar值“0.00”转换为数据类型int时,转换失败,sql,sql-server,sql-server-2005,Sql,Sql Server,Sql Server 2005,将此行添加到我的查询中时: convert(varchar(20), convert(varchar(20), sum(case when tsr.other like '%aa%' then tsr.block1 else 0 end) + sum(case when tsr.other like '%aa%' then tsr.block2 else 0 end) + sum(case when tsr.other like '%aa%' then tsr.block3 else 0 end
convert(varchar(20), convert(varchar(20),
sum(case when tsr.other like '%aa%' then tsr.block1 else 0 end) +
sum(case when tsr.other like '%aa%' then tsr.block2 else 0 end) +
sum(case when tsr.other like '%aa%' then tsr.block3 else 0 end) +
sum(case when tsr.other like '%aa%' then tsr.block4 else 0 end)) * 450)
我收到以下错误消息:
将varchar值“0.00”转换为数据时,转换失败
int型
块列中的数据为天-例如10.0
有什么想法吗
我已经修好了,只是把450改成了450.0
使用varchars的原因是,这只是多个联合select语句中1个语句的1行 10.0不是整数-它是小数 试一试
从小数到整数的转换是隐式的。忘了这一点,回答了我自己的问题。将450更改为450.0并删除了错误消息。看起来您正在尝试将varchar20乘以450。否?尝试如下。。。那么Casttsr.block2作为float-else 0.0 end为什么要对一列求和,将结果转换为VARCHAR,然后将其乘以450???当然,当然,如果有什么你应该明确地对数字施加影响的话,而不是相反的方式?不需要成为宽伙伴,我只是在学习。
'10.0' isn't an int/decimal - it's a varchar .
do any mathematical calculation only on decimal/numeric/float/int values.
SELECT convert(varchar(20), convert(decimal(10,2), sum(case when
tsr.other like '%aa%' then convert(decimal(10,2),tsr.block1) else 0
end) + sum(case when tsr.other like '%aa%' then
convert(decimal(10,2),tsr.block2) else 0 end) + sum(case when
tsr.other like '%aa%' then convert(decimal(10,2),tsr.block3) else 0
end) + sum(case when tsr.other like '%aa%' then
convert(decimal(10,2),tsr.block4) else 0 end)) * 450)
'10.0' isn't an int/decimal - it's a varchar .
do any mathematical calculation only on decimal/numeric/float/int values.
SELECT convert(varchar(20), convert(decimal(10,2), sum(case when
tsr.other like '%aa%' then convert(decimal(10,2),tsr.block1) else 0
end) + sum(case when tsr.other like '%aa%' then
convert(decimal(10,2),tsr.block2) else 0 end) + sum(case when
tsr.other like '%aa%' then convert(decimal(10,2),tsr.block3) else 0
end) + sum(case when tsr.other like '%aa%' then
convert(decimal(10,2),tsr.block4) else 0 end)) * 450)