Rurangwa
Rurangwa

Reputation: 11

Operand data type varchar(max) is invalid for divide operator

Below is the query I am trying to run using Microsoft SQL Server Management Studio:

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

Upvotes: 0

Views: 1367

Answers (2)

Gordon Linoff
Gordon Linoff

Reputation: 1270463

One or both of your values are strings. Use try_convert() to convert them to an appropriate type. The specific type is not clear, but something like:

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

Upvotes: 1

Somendra Kanaujia
Somendra Kanaujia

Reputation: 824

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

Upvotes: 0

Related Questions