Solved

Convert from  Nvarchar to Float

Posted on 2011-03-22
8
733 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
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
 
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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
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

Free Trending Threat Insights Every Day

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.

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.
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

746 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

11 Experts available now in Live!

Get 1:1 Help Now