NZ function - can't get to work

G

Guest

Hi,

I have 2 tables - a main table (tbl_Opportunity) and a look-up table
(tbl_AMContacts). I have a field in each (AllianceMgr) that links the two
tables together (AllianceMgr is the primary key on the AMContacts table).
I'm trying to do a query that combines all of this data together so I can
display it on a form. But, if the AllianceMgr is blank on the main table,
when I do the query it doesn't display any of those records. I want it to
display all records -- even if there is a null in the AllianceMgr field. I
tried using the nz function, but couldn't seem to get it to work. Here is
what I was trying:

SELECT tbl_Opportunity.Opportunity_ID, tbl_Opportunity.AccountName,
tbl_Opportunity.EngagementDesc, tbl_Opportunity.AllianceMgr,
Nz(tbl_AMContacts.Title,0), Nz(tbl_AMContacts.Phone1,0)
FROM tbl_AMContacts INNER JOIN tbl_Opportunity ON tbl_AMContacts.AMName =
tbl_Opportunity.AllianceMgr;

Thanks!
Heather
 
K

Ken Snell \(MVP\)

Use a outer join (here, a LEFT JOIN):

SELECT tbl_Opportunity.Opportunity_ID, tbl_Opportunity.AccountName,
tbl_Opportunity.EngagementDesc, tbl_Opportunity.AllianceMgr,
Nz(tbl_AMContacts.Title,0), Nz(tbl_AMContacts.Phone1,0)
FROM tbl_AMContacts LEFT JOIN tbl_Opportunity ON tbl_AMContacts.AMName =
tbl_Opportunity.AllianceMgr;
 
G

Guest

I tried that... It brought back more records, but the new ones that it
brought back were just blank across the board. Each line should at least
have an OpportunityID, and AccountName even if the AllianceMgr is null. Any
other ideas?

Thanks!!
 
K

Ken Snell \(MVP\)

Not knowing exactly what you're seeking, perhaps the JOIN is going in the
wrong direction for what you seek. Try one of these:

SELECT tbl_Opportunity.Opportunity_ID, tbl_Opportunity.AccountName,
tbl_Opportunity.EngagementDesc, tbl_Opportunity.AllianceMgr,
Nz(tbl_AMContacts.Title,0), Nz(tbl_AMContacts.Phone1,0)
FROM tbl_AMContacts RIGHT JOIN tbl_Opportunity ON tbl_AMContacts.AMName =
tbl_Opportunity.AllianceMgr;


SELECT tbl_Opportunity.Opportunity_ID, tbl_Opportunity.AccountName,
tbl_Opportunity.EngagementDesc, tbl_Opportunity.AllianceMgr,
Nz(tbl_AMContacts.Title,0), Nz(tbl_AMContacts.Phone1,0)
FROM tbl_Opportunity LEFT JOIN tbl_AMContacts ON tbl_Opportunity.AllianceMgr
=
tbl_AMContacts.AMName;
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

NZ function 1
Nz function 0
Nz function 6
NZ function 1
Nz problem 9
Can I use an IIF statement with the NZ function? 2
Using NZ Function to return ALL records 4
DLookup and Nz 0

Top