Solved

Convert from  Nvarchar to Float

Posted on 2011-03-22
8
739 Views
Last Modified: 2012-06-27
select Applicant_IDNumber,[ID Number]
from Applicant A
join  mis.dbo.Staff_Report SR On SR.[ID Number]= A.Applicant_IDNumber

Open in new window


Msg 8114, Level 16, State 5, Line 1
Error converting data type nvarchar to float.

Hi  i need to convert Applicant_IDNumber to a float(currently it is a Nvarchar) [ID Number] is a float if i convert this to a nvachar it picks up no matches when there are matches

0
Comment
Question by:Davesm
[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
8 Comments
 
LVL 5

Expert Comment

by:Angelgeo
ID: 35196221
select Applicant_IDNumber,[ID Number]
from Applicant A
join  mis.dbo.Staff_Report SR On SR.[ID Number]= cast(A.Applicant_IDNumber as float)
0
 

Author Comment

by:Davesm
ID: 35196243
Hi i still get this error

Msg 8114, Level 16, State 5, Line 1
Error converting data type nvarchar to float.
0
 
LVL 19

Expert Comment

by:Rikin Shah
ID: 35196259
select Applicant_IDNumber,[ID Number]
from Applicant A
join  mis.dbo.Staff_Report SR On CAST(SR.[ID Number] AS NVARCHAR)= A.Applicant_IDNumber

Open in new window

0
Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

 
LVL 19

Expert Comment

by:Bhavesh Shah
ID: 35196261
Hi,

try this one
select Applicant_IDNumber,[ID Number]
from Applicant A
join  mis.dbo.Staff_Report SR On cast(SR.[ID Number] as varchar)= cast(A.Applicant_IDNumber as varchar)

Open in new window

0
 
LVL 5

Expert Comment

by:Angelgeo
ID: 35196287
select Applicant_IDNumber,[ID Number]
from Applicant A
join  mis.dbo.Staff_Report SR On SR.[ID Number]= cast(replace(A.Applicant_IDNumber,',','.') as float)

or

select Applicant_IDNumber,[ID Number]
from Applicant A
join  mis.dbo.Staff_Report SR On SR.[ID Number]= cast(isnull(replace(A.Applicant_IDNumber,',','.'),0) as float)
0
 
LVL 19

Expert Comment

by:Bhavesh Shah
ID: 35196302
Hi Angelgeo,

Small note to take....

Its nvarchar column, so column could contain any characters..... =)


- Bhavesh
0
 
LVL 23

Expert Comment

by:OP_Zaharin
ID: 35196321
hi Davesm,

- this code use a CONVERT() function. since ID Number itself is a FLOAT, we convert the A.Applicant_IDNumber to FLOAT. do give it a try:

select Applicant_IDNumber,[ID Number]
from Applicant A
join  mis.dbo.Staff_Report SR On SR.[ID Number] = CONVERT(FLOAT, A.Applicant_IDNumber)

Open in new window

0
 
LVL 50

Accepted Solution

by:
Lowfatspread earned 500 total points
ID: 35196480
select applicant_idnumber,[id number]
from (select convert(float,applicant_idnumber) as applicant_idnumber
 from applicant where isnumeric(applicant_idnumber)=1) as a
inner join mis.dbo.Staff_Report SR On SR.[ID Number] = A.Applicant_IDNumber

but it is not a sensible arrangement to have ids using floating point numbers....
or to mix char and float datatypes like this....
















0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Why do I get extra rows when I do inner join? 12 43
SQL Server 2012 express 24 46
Format Date fields 11 64
Find unused columns in a table 12 97
This article will describe one method to parse a delimited string into a table of data.   Why would I do that you ask?  Let's say that you need to pass multiple parameters into a stored procedure to search for.  For our sake, we'll say that we wa…
by Mark Wills Attending one of Rob Farley's seminars the other day, I heard the phrase "The Accidental DBA" and fell in love with it. It got me thinking about the plight of the newcomer to SQL Server...  So if you are the accidental DBA, or, simp…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

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