Trying to sum two columns in SQL Server results in error message

Viewed 4303

I'm trying to calculate the sum of two separate fields with the query

select sum(percent12 + percent21) as total
from finalquery

but I keep getting this error:

Msg 8117, Level 16, State 1, Line 535

Operand data type varchar is invalid for sum operator.

However, if I do:

select percent12 + percent21 as total
from finalquery

I get:

(total)
50.0040.00
25.0025.00
100.0 0.00
100.0 0.00
100.0 0.00

How can I fix this?

4 Answers
Related