Solved

implicit conversion of nvarchar to int

Posted on 2015-01-01
7
248 Views
Last Modified: 2015-01-03
In MSSQL 2008, I have a table called tblmaster with an int column called "weight"

UPDATE documenter.dbo.tblmaster
SET  
  weight = '55.0'
where Account=6199155;

Open in new window


and it gives me an error
Msg 245, Level 16, State 1, Line 2
Conversion failed when converting the varchar value '55.0' to data type int.

OK, so I try to cast it with

UPDATE documenter.dbo.tblmaster
SET  
  weight = CAST('55.0' as INT)
where Account=6199155;

Open in new window


and

UPDATE documenter.dbo.tblmaster
SET  
  weight = convert(int, '55.0')
where Account=6199155;

Open in new window


but no luck.

What gives?
0
Comment
Question by:mankowitz
  • 4
  • 3
7 Comments
 
LVL 33

Expert Comment

by:Mike Eghtebas
ID: 40526936
UPDATE documenter.dbo.tblmaster
SET  
  weight = 55.0
where Account=6199155;
0
 
LVL 24

Author Comment

by:mankowitz
ID: 40526946
Sorry, I should have mentioned that the constraint is that the '55.0' is supplied by another program which I am not able to modify. I am looking for a way to convert '55.0' into 55
0
 
LVL 33

Accepted Solution

by:
Mike Eghtebas earned 500 total points
ID: 40526954
What you have:

UPDATE documenter.dbo.tblmaster
SET  
  weight = CAST('55.0' as INT)
where Account=6199155;

is correct. Make sure field weight is also integer. The choice of Integer for weight field is unlikely.

try:
UPDATE documenter.dbo.tblmaster
SET  
  weight = CAST('55.0' as float)
where Account=6199155;
0
What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
LVL 24

Author Closing Comment

by:mankowitz
ID: 40526976
Wow... that is completely nonintuitive. Thanks!!! Incidentally, the weight field really is an integer.
0
 
LVL 33

Expert Comment

by:Mike Eghtebas
ID: 40526991
you mean weight = CAST('55.0' as float) worked for you?
0
 
LVL 24

Author Comment

by:mankowitz
ID: 40529829
Yes... I thought that's why you suggested it as an answer. For whatever reason, you can't cast '55.0' as an INT, but you can cast it as a float, which, apparently is implicitly cast as an int.
0
 
LVL 33

Expert Comment

by:Mike Eghtebas
ID: 40529831
Oh, I didn't know I was (accidentally) this good. LOL

I assumed your weight column must be a float. This is why I suggested it. Well, as long as it worked for you at the end and we both leaned something about the conversion.
0

Featured Post

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

In this article I will describe the Backup & Restore method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
In this article I will describe the Copy Database Wizard method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

758 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now