Solved

int and varchar joined

Posted on 2011-03-17
4
391 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
[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
  • 2
4 Comments
 
LVL 32

Accepted Solution

by:
Ephraim Wangoya 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 41

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:Ephraim Wangoya
ID: 35161201

True, we acquire more knowledge each day.
0
 

Author Closing Comment

by:rgb192
ID: 35165819
thanks
0

Featured Post

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Help with SQL joins 9 56
Error when saving to sql table a '/' 5 31
Sql query 107 87
Clone table from one server.database to another server.database 24 49
I am showing a way to read/import the excel data in table using SQL server 2005... Suppose there is an Excel file "Book1" at location "C:\temp" with column "First Name" and "Last Name". Now to import this Excel data into the table, we will useā€¦
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.
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

756 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