SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 operand data type nvarchar is invalid error
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

dbonneau
Yak Posting Veteran

50 Posts

Posted - 11/11/2012 :  05:07:47  Show Profile  Reply with Quote
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
Flowing Fount of Yak Knowledge

5155 Posts

Posted - 11/11/2012 :  07:16:03  Show Profile  Reply with Quote
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 - 11/11/2012 :  18:11:25  Show Profile  Reply with Quote
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

India
22761 Posts

Posted - 11/17/2012 :  03:20:44  Show Profile  Send madhivanan a Yahoo! Message  Reply with Quote
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
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.03 seconds. Powered By: Snitz Forums 2000