Solved

SQL query: Join on similiar fields

Posted on 2009-03-30
3
207 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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

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

The Delta outage: 650 cancelled flights, more than 1200 delayed flights, thousands of frustrated customers, tens of millions of dollars in damages – plus untold reputational damage to one of the world’s most trusted airlines. All due to a catastroph…
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 set up a backup for SQL Server using a Maintenance Plan and how to schedule the job into SQL Server Agent.
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…

739 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