Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Convert from  Nvarchar to Float

Posted on 2011-03-22
8
Medium Priority
?
748 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
Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

 
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 2000 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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

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…
Data architecture is an important aspect in Software as a Service (SaaS) delivery model. This article is a study on the database of a single-tenant application that could be extended to support multiple tenants. The application is web-based develope…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …

730 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