Solved

implicit conversion of nvarchar to int

Posted on 2015-01-01
7
259 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
7 Comments
 
LVL 34

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 34

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
Use Case: Protecting a Hybrid Cloud Infrastructure

Microsoft Azure is rapidly becoming the norm in dynamic IT environments. This document describes the challenges that organizations face when protecting data in a hybrid cloud IT environment and presents a use case to demonstrate how Acronis Backup protects all data.

 
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 34

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 34

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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Naughty Me. While I was changing the database name from DB1 to DB_PROD1 (yep it's not real database name ^v^), I changed the database name and notified my application fellows that I did it. They turn on the application, and everything is working. A …
How to leverage one TLS certificate to encrypt Microsoft SQL traffic and Remote Desktop Services, versus creating multiple tickets for the same server.
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

749 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