SQL subtract two columns giving error- Invalid operator for data type. Operator equals subtract, type equals nvarchar

397 views Asked by At

I am trying to subtract 2 columns in a database table and call the column calc, and its giving me an error:

Invalid operator for data type. Operator equals subtract, type equals nvarchar.

Anyone shed some light on this? Thanks.


SELECT  
      ,[old]
      ,[new]
       , (new - old) as calc
    FROM database

database:

data

what i want to show with calc column:

enter image description here

1

There are 1 answers

4
Juanø On

Try:

SELECT  
  ,[old]
  ,[new]
   , (numeric(new) - numeric(old)) as calc
FROM database