Solved

SQL query: Join on similiar fields

Posted on 2009-03-30
3
208 Views
Last Modified: 2012-05-06
Greetings Experts,

I have a situation where I need to join tables on a fields with different values.   In one table, the patient# uses hyphens and the second table does not.  I am joining the tables on patient#.  Any idea how i can do this?  Maybe i can create another table/qry/view that strips out the hyphen?
Here is an example of my problem,

Table 1                              
Study                Patient#      
StudyA             A01-101
StudyA             A02-103
StudyA             A101-103


Table 2
Study                Patient#      
StudyA             A01101
StudyA             A02103
StudyA             A101103

Thanks.



                 
0
Comment
Question by:Pharmica
[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
3 Comments
 
LVL 143

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 500 total points
ID: 24022302
you could consider this:
select ... 
  from table1 t1
  join table2 t2
    on replace(t1.patient#, '-', '') = t2.Patient#

Open in new window

0
 
LVL 6

Expert Comment

by:RPCIT
ID: 24022303
if it's just joining without the hyphens.. this should work.

SELECT *
FROM Table1
JOIN Table2
     ON REPLACE(Table1.Patient#,'-','') = Table2.Patient#
0
 

Author Closing Comment

by:Pharmica
ID: 31564496
Thanks for your help!
0

Featured Post

Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

Question has a verified solution.

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

For both online and offline retail, the cross-channel business is the most recent pattern in the B2C trade space.
Ever wondered why sometimes your SQL Server is slow or unresponsive with connections spiking up but by the time you go in, all is well? The following article will show you how to install and configure a SQL job that will send you email alerts includ…
Viewers will learn how to use the SELECT statement in SQL and will be exposed to the many uses the SELECT statement has.
Viewers will learn how to use the UPDATE and DELETE statements to change or remove existing data from their tables. Make a table: Update a specific column given a specific row using the UPDATE statement: Remove a set of values using the DELETE s…

632 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