Solved

Convert from  Nvarchar to Float

Posted on 2011-03-22
8
743 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
Get free NFR key for Veeam Availability Suite 9.5

Veeam is happy to provide a free NFR license (1 year, 2 sockets) to all certified IT Pros. The license allows for the non-production use of Veeam Availability Suite v9.5 in your home lab, without any feature limitations. It works for both VMware and Hyper-V environments

 
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

Three Reasons Why Backup is Strategic

Backup is strategic to your business because your data is strategic to your business. Without backup, your business will fail. This white paper explains why it is vital for you to design and immediately execute a backup strategy to protect 100 percent of your data.

Question has a verified solution.

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

I've encountered valid database schemas that do not have a primary key.  For example, I use LogParser from Microsoft to push IIS logs into a SQL database table for processing and analysis.  However, occasionally due to user error or a scheduled task…
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.
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

617 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