Solved

int and varchar joined

Posted on 2011-03-17
4
389 Views
Last Modified: 2012-05-11
join an int and varchar column

but the column that is varchar has words sometimes
I do not want that joined

0
Comment
Question by:rgb192
  • 2
4 Comments
 
LVL 32

Accepted Solution

by:
ewangoya earned 250 total points
ID: 35160427

select *
from tableA
inner join TableB on ( (Cast(TableB.Varhcharfield as Integer) = TableA.IntegerField)
                                  and (ISNUMERIC(TableB.Varhcharfield) = 1))
0
 
LVL 40

Assisted Solution

by:Sharath
Sharath earned 250 total points
ID: 35160714
ewangoya, converting to int will fail if the asker has , or . in the data. check this example by converting to INT.
I prefer converting to MONEY in such cases.
declare @table1 table(col1 int)
declare @table2 table(col2 varchar(10))
insert @table1 values(10),(20)
insert @table2 values ('10'),('23.00'),('123,234'),('invalid')
select *
  from @table1 t1
  join @table2 t2 
    on t1.col1 = convert(money,t2.col2)
 where ISNUMERIC(t2.col2) = 1

Open in new window

0
 
LVL 32

Expert Comment

by:ewangoya
ID: 35161201

True, we acquire more knowledge each day.
0
 

Author Closing Comment

by:rgb192
ID: 35165819
thanks
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Suggested Solutions

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.
This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

789 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