[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

joining one table to multiple fields?

Posted on 2013-10-30
4
Medium Priority
?
192 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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

Access custom database properties are useful for storing miscellaneous bits of information in a format that persists through database closing and reopening.  This article shows how to create and use them.
One of the most important things in an application is the query performance. This article intends to give you good tips to improve the performance of your queries.
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.
With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…

656 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