Solved

SQL query: Join on similiar fields

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

Migrating Your Company's PCs

To keep pace with competitors, businesses must keep employees productive, and that means providing them with the latest technology. This document provides the tips and tricks you need to help you migrate an outdated PC fleet to new desktops, laptops, and tablets.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
How to count the days a record spends in a step 21 51
SSAS Store Forecasting data in the cube 1 20
SQL Server / Update DB? 22 38
RAISERROR WITH NOWAIT 2 18
I'm trying, I really am. But I've seen so many wrong approaches involving date(time) boundaries I despair about my inability to explain it. I've seen quite a few recently that define a non-leap year as 364 days, or 366 days and the list goes on. …
Composite queries are used to retrieve the results from joining multiple queries after applying any filters. UNION, INTERSECT, MINUS, and UNION ALL are some of the operators used to get certain desired results.​
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
Using examples as well as descriptions, and references to Books Online, show the documentation available for date manipulation functions and by using a select few of these functions, show how date based data can be manipulated with these functions.

830 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