Solved

int and varchar joined

Posted on 2011-03-17
4
396 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

Guide to Performance: Optimization & Monitoring

Nowadays, monitoring is a mixture of tools, systems, and codes—making it a very complex process. And with this complexity, comes variables for failure. Get DZone’s new Guide to Performance to learn how to proactively find these variables and solve them before a disruption occurs.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Set the max value for a column 7 43
Format Date fields 11 64
Need help in debugging a UDF results 7 72
SQL Server 2005 database messed up. Can it be fixed? 4 38
This article will describe one method to parse a delimited string into a table of data.   Why would I do that you ask?  Let's say that you need to pass multiple parameters into a stored procedure to search for.  For our sake, we'll say that we wa…
Introduction: When running hybrid database environments, you often need to query some data from a remote db of any type, while being connected to your MS SQL Server database. Problems start when you try to combine that with some "user input" pass…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

751 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