?
Solved

implicit conversion of nvarchar to int

Posted on 2015-01-01
7
Medium Priority
?
261 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 2000 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
Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

 
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: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

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

     When we have to pass multiple rows of data to SQL Server, the developers either have to send one row at a time or come up with other workarounds to meet requirements like using XML to pass data, which is complex and tedious to use. There is a …
Hi all, It is important and often overlooked to understand “Database properties”. Often we see questions about "log files" or "where is the database" and one of the easiest ways to get general information about your database is to use “Database p…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

752 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