?
Solved

joining one table to multiple fields?

Posted on 2013-10-30
4
Medium Priority
?
188 Views
Last Modified: 2014-01-08
I have one table that I need to join to a second table but am having trouble getting the results I want..


ltblGSA_Orders_IOrders                               ltblQBooks_Customer
cust_name                                                     name
email                                                              email (this field is a memo hence the sql that follows)

I have a left join from ltblgsa_orders_IOrders.email to ltblqbooks_Customer.email (should I add another join from cust_name to name?)

an example of the data contained is:

ltblGSA_Orders_IOrders                               ltblQBooks_Customer
JOHN SMITH                                                  Smith, John
john.smith@abc.com                                   jsmith@def.com

here's the expression I've been using but it hasn't been working:

IIf(
      [ltblGSA_Orders_IOrders].[cust_email]=cstr([ltblQBooks_Customer].[email] & ""),
            [ltblQBooks_Customer]![Name],
IIf(
      StrConv(Nz(Mid([CUST_NAME],InStr([CUST_NAME]," ")+1)),3) & ", " & StrConv(Nz(Left([CUST_NAME],InStr([CUST_NAME]," ")-1)),3)=[ltblQBooks_Customer]![Name]  ,
            "DuplicateNameDifferentCustomer" & StrConv(Nz(Mid([CUST_NAME],InStr([CUST_NAME]," ")+1)),3) & ", " & StrConv(Nz(Left([CUST_NAME],InStr([CUST_NAME]," ")-1)),3),
                        StrConv(Nz(Mid([CUST_NAME],InStr([CUST_NAME]," ")+1)),3) & ", " & StrConv(Nz(Left([CUST_NAME],InStr([CUST_NAME]," ")-1)),3)
))

hopefully the above isn't confusing.

thanks for your help!
0
Comment
Question by:intsup
[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
4 Comments
 
LVL 25

Expert Comment

by:chaau
ID: 39613079
What are these Iif statements? Are these for the Column expression or they are the conditions you use for the JOIN?
0
 
LVL 8

Expert Comment

by:virtuadept
ID: 39624432
It looks like you want to join 2 tables but those 2 tables do not have a common identifier to join against. In other words, you have 2 tables that have a "name" column but they do not store the name consistantly and not in the same way. For this I say, good luck with that. What you need to do, really, is create some new columns on both tables and write some update statements so that you will get these new columns in the same format on both tables so that you can use those columns to join against. And put an index on them for these new columns also.
0
 
LVL 5

Accepted Solution

by:
Lawrence Barnes earned 2000 total points
ID: 39670652
I understand that sometimes databases are inherited and you have to work with what you have.  In the long run some structure (noted by virtuadept) would help.  But in the short term:

Emails are fairly unique and you are left joining on them so you will see all orders with matching emails.  But I suppose email addresses can be recycled so you want to consider comparing names, since they are in both of the tables...just in case.  In the attached I've created goofy@aol.com as an email address that switched owners.

Since you are using an IIF I'm assuming you are doing this in Access which is what I have attached.

To this end...Regarding your code:  In the table references above you have the field ltblGSA_Orders_IOrders.email.  But in your query you refer to ltblGSA_Orders_IOrders.cust_email and that is why that statement didn't work.  Here's one that does (and is in the attached database in Query1.YourQueryName.)
SELECT ltblGSA_Orders_IOrders.cust_name, ltblGSA_Orders_IOrders.email, ltblQBooks_Customer.name, ltblQBooks_Customer.email AS CustomerEmail, IIf([ltblGSA_Orders_IOrders].[email]=CStr([ltblQBooks_Customer].[email] & ""),[ltblQBooks_Customer]![Name],IIf(StrConv(Nz(Mid([CUST_NAME],InStr([CUST_NAME]," ")+1)),3) & ", " & StrConv(Nz(Left([CUST_NAME],InStr([CUST_NAME]," ")-1)),3)=[ltblQBooks_Customer]![Name],"DuplicateNameDifferentCustomer" & StrConv(Nz(Mid([CUST_NAME],InStr([CUST_NAME]," ")+1)),3) & ", " & StrConv(Nz(Left([CUST_NAME],InStr([CUST_NAME]," ")-1)),3),StrConv(Nz(Mid([CUST_NAME],InStr([CUST_NAME]," ")+1)),3) & ", " & StrConv(Nz(Left([CUST_NAME],InStr([CUST_NAME]," ")-1)),3))) AS AltName
FROM ltblGSA_Orders_IOrders LEFT JOIN ltblQBooks_Customer ON ltblGSA_Orders_IOrders.email = ltblQBooks_Customer.email;

Open in new window

Database3.accdb
0
 

Author Comment

by:intsup
ID: 39765167
i'm afraid I got caught up with two other projects and wasn't able to work on this one at all so i'll close for now until I get back to this one..

thanks for the input, though!
0

Featured Post

Percona Live Europe 2017 | Sep 25 - 27, 2017

The Percona Live Open Source Database Conference Europe 2017 is the premier event for the diverse and active European open source database community, as well as businesses that develop and use open source database software.

Question has a verified solution.

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

This article describes a method of delivering Word templates for use in merging Access data to Word documents, that requires no computer knowledge on the part of the recipient -- the templates are saved in table fields, and are extracted and install…
Code that checks the QuickBooks schema table for non-updateable fields and then disables those controls on a form so users don't try to update them.
Basics of query design. Shows you how to construct a simple query by adding tables, perform joins, defining output columns, perform sorting, and apply criteria.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
Suggested Courses

762 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