Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 operand data type nvarchar is invalid error

Author  Topic 

dbonneau
Yak Posting Veteran

50 Posts

Posted - 2012-11-11 : 05:07:47
Hi,

I have a following syntax but I get error
"operand data type nvarchar is invalid for subtract operator "

update my_table
set Total_field = ( Field_A - Field_B) from my_table;

Thank you

sunitabeck
Master Smack Fu Yak Hacker

5155 Posts

Posted - 2012-11-11 : 07:16:03
You will need to cast field_a and field_b to a numeric type if they are of character type - for example
update my_table
set Total_field = ( cast(Field_A as float) - cast(Field_B as float)) from my_table;
Go to Top of Page

dbonneau
Yak Posting Veteran

50 Posts

Posted - 2012-11-11 : 18:11:25
quote:
Originally posted by sunitabeck

You will need to cast field_a and field_b to a numeric type if they are of character type - for example
update my_table
set Total_field = ( cast(Field_A as float) - cast(Field_B as float)) from my_table;




Thank you so much ! It works good !
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2012-11-17 : 03:20:44
But why do you store numerals in character datatypes? Always use proper datatype based on the nature of data

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -