Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Receiving error:Error converting data type nvarchar to float

Status
Not open for further replies.

kdjonesmtb2

Technical User
Nov 19, 2012
93
US
I have an excel file that I imported in SQL Server 2008 R2

The following field produces this error when I try to convert it

Error converting data type nvarchar to float

,cast(O.ME016 AS float(255)) AS NHP_ME016


ME016 is a date field that imported from Excel in the default nvarchar data type

Do I need to recreate the table with the wizard or can I use the case function?

The cast code is not working

Thanks
 
The float datatype does not take a size argument. Converting to float(255) should throw an error. Try converting to just float.
Code:
,cast(O.ME016 AS float) AS NHP_ME016

Secondly, converting a string formatted as a date to a float will not work. For example:
Code:
select cast ('1/1/2013' as float)
will throw an error, because '1/1/2013' is not a valid float number. Why are you trying to convert dates to floats?
 
Hello,

I think the issue is a different field -

When I comment out the following line my code executes

The field in question is BEME016 which is a phone number field format 9999999999

--,BEME016Variance = Case
--when O.BEME016 = C.BEME016 then '1' Else '0'
--End

Thanks
 
Phone numbers probably should not be treated as numbers in the traditional sense, unless you need to add a pair of phone numbers together. i would leave them as strings.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top