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)
 Update query convert nvarchar(50) to numeric(18, 0

Author  Topic 

taunt
Posting Yak Master

128 Posts

Posted - 2014-07-15 : 14:23:01
Hello I'm trying to convert a nvarchar(50) to numeric(18, 0). This is my query:


UPDATE Aupdate
SET VID = Label.VID
FROM Label INNER JOIN
Aupdate ON Label.LabelCodeA = Aupdate.LabelAbbr


The issue is Label.VID is nvarchar(50) and Aupdate.VID is numeric(18, 0). What would be the best way to convert nvar to numeric? Should I use cast? The odd thing is that it use to work and all the sudden I get that error.

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2014-07-15 : 14:36:12
Yes CAST or CONVERT, but I suspect it's a data issue where it can't be converted to numeric. You can use the ISNUMERIC function to find the varchar data that is not numeric.

Tara Kizer
SQL Server MVP since 2007
http://weblogs.sqlteam.com/tarad/
Go to Top of Page

taunt
Posting Yak Master

128 Posts

Posted - 2014-07-15 : 14:44:04
Yep, I looked at the Label table and someone put letters in the field I was trying to convert to a numeric. That was the issue. I fixed the bad data and it worked fine.

Thanks
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2014-07-15 : 14:50:23


Tara Kizer
SQL Server MVP since 2007
http://weblogs.sqlteam.com/tarad/
Go to Top of Page
   

- Advertisement -