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

问题描述 投票:0回答:2

以下是试图使用Microsoft Server Server Studio运行的查询:

update [SG report] 
set [percentage_paid] =  ([Savings This Season (All)] / [Savings Goal Amount]) * 100
sql ssms
2个回答
0
投票
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

0
投票

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

update [SG report] 
    set [percentage_paid] =  (try_convert(float, [Savings This Season (All)])  * 100 /
                              try_convert(float, [Savings Goal Amount])
                             );
© www.soinside.com 2019 - 2024. All rights reserved.