操作数数据类型varchar(max)对于除法运算符无效

liwlm1x9  于 2021-08-09  发布在  Java
关注(0)|答案(2)|浏览(964)

下面是我尝试使用microsoft sql server management studio运行的查询:

update [SG report] 
set [percentage_paid] = ([Savings This Season (All)] / [Savings Goal Amount]) * 100
7ivaypg9

7ivaypg91#

一个或两个值都是字符串。使用 try_convert() 将它们转换为适当的类型。具体的类型不清楚,但类似于:

update [SG report] 
    set [percentage_paid] =  (try_convert(float, [Savings This Season (All)])  * 100 /
                              try_convert(float, [Savings Goal Amount])
                             );
mpbci0fu

mpbci0fu2#

update [SG report] 
set [percentage_paid] =  ([Savings This Season (All)] / [Savings Goal Amount]) * 100
where isnumeric([Savings This Season (All)])=1 and isnumeric([Savings Goal Amount])=1

相关问题