Solved

SQL query: Join on similiar fields

Posted on 2009-03-30
3
205 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
3 Comments
 
LVL 142

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

Microsoft Certification Exam 74-409

VeeamĀ® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

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

Suggested Solutions

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.
For both online and offline retail, the cross-channel business is the most recent pattern in the B2C trade space.
Via a live example, show how to extract information from SQL Server on Database, Connection and Server properties
Via a live example, show how to set up a backup for SQL Server using a Maintenance Plan and how to schedule the job into SQL Server Agent.

809 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