Solved

Query Help, Showing Records Not In table

Posted on 2014-01-05
6
322 Views
Last Modified: 2014-01-05
Experts, I have been having troubles with these queries.  I dont know what I am doing wrong.  It is quite simple but something seems to not be working.

If you look at the pared down db.
Open the query

It shows 2 records that are NOT IN tblLetterOfCredit on LCNo and L/C Ref
However, both of those records are in tblLetterOfCredit.
The only difference between them is a "-" dash but the function (StrippedChar) is suppose to remove the "-" and compare but the query still shows those 2 records as NOT IN tblLetterOfCredit.

What is happening?  These queries are about to drive me nuts because I think I understand what is happening but then what I learned goes out the window (as in this example).  

Please open the pared down db.  There is probably a simple answer to this that I cant see.
EE.accdb
0
Comment
Question by:pdvsa
  • 3
  • 3
6 Comments
 
LVL 61

Accepted Solution

by:
mbizup earned 500 total points
ID: 39758193
Check my explanation of unmatched queries, using LEFT JOINs in your earlier question, and try this since you're using a RIGHT JOIN:

SELECT [Import-DnB].[L/C Ref], tblLetterOfCredit.LCNo, StrippedChar([L/C Ref]) AS [LC Ref DNB], StrippedChar([L/C Ref]) AS [LCRef_Import-Dnb_Me], StrippedChar([LCNo] & "") AS LCNo_tblLetterOfCredit_Me
FROM tblLetterOfCredit RIGHT JOIN [Import-DnB] ON StrippedChar(tblLetterOfCredit.LCNo & "" )  = StrippedChar( [Import-DnB].[L/C Ref] & "")
WHERE  tblLetterOfCredit.LCNo IS NULL

Open in new window

0
 

Author Comment

by:pdvsa
ID: 39758269
Mbizup:  why do I get this error?   I copied and pasted from above.

Error

What makes it a RIGHT or LEFT qry?  In the query code above, there is not line drawn between the two tables but I do see it is a RIGHT join.  Maybe it doesnt show the line because of the error?

thank you
0
 
LVL 61

Expert Comment

by:mbizup
ID: 39758282
It won't display in design view because of the functions that you need to make the comparison you want (not exactly an error).

Have you tried going directly from SQL to datasheet view?


--->> What makes it a RIGHT or LEFT qry?

Right and Left specify from which table ALL records are to be pulled.

eg in this JOIN, all records are pulled from table1 and only matching records from table2:

Table1 LEFT JOIN table2 ON Table1.ID = Table2.ID

Open in new window


Conversely, in this JOIN, all records are pulled from table2 and only matching records from table1:

Table1 RIGHT JOIN table2 ON Table1.ID = Table2.ID

Open in new window



Without design view as a visual aid, the RIGHT or LEFT simply means which side of the JOIN a table appears on in SQL view.
0
The Eight Noble Truths of Backup and Recovery

How can IT departments tackle the challenges of a Big Data world? This white paper provides a roadmap to success and helps companies ensure that all their data is safe and secure, no matter if it resides on-premise with physical or virtual machines or in the cloud.

 

Author Comment

by:pdvsa
ID: 39758390
<Have you tried going directly from SQL to datasheet view?

Yes, I dont get the error.  

Shouldnt there be a line drawn between the 2 tables though?  It says RIGHT join so I am thinking there should be a line showing the relationship.

The bold and underlined is not needed, correct?  Also, if I delete simply the column I get errors when run...I have to delete the bolded below within the SQL.  

SELECT [Import-DnB].[L/C Ref], tblLetterOfCredit.LCNo, StrippedChar([L/C Ref]) AS [LC Ref DNB], StrippedChar([L/C Ref]) AS [LCRef_Import-Dnb_Me], StrippedChar([LCNo] & "") AS LCNo_tblLetterOfCredit_Me
FROM tblLetterOfCredit RIGHT JOIN [Import-DnB] ON StrippedChar(tblLetterOfCredit.LCNo & "" )  = StrippedChar( [Import-DnB].[L/C Ref] & "")
WHERE  tblLetterOfCredit.LCNo IS NULL

This is the final (I removed those columns from above):
SELECT [Import-DnB].[L/C Ref], tblLetterOfCredit.LCNo
FROM tblLetterOfCredit RIGHT JOIN [Import-DnB] ON StrippedChar(tblLetterOfCredit.LCNo & "" )  = StrippedChar( [Import-DnB].[L/C Ref] & "")
WHERE  tblLetterOfCredit.LCNo IS NULL

Open in new window



I really appreciate your explanations.  It seems like I would be best served using WHERE condition as Is Null in the testing criteria.
0
 
LVL 61

Expert Comment

by:mbizup
ID: 39758400
Did removing the underlined code work in SQL and datasheet view?

if so you are good to go.

The lack of a line in design view is not a problem.  This query as well as  other types of queries simply will not render in design view even though they are syntactically fine.  When that happens, you just need to stick to SQL and datasheet view (and not try to work in design view or worry about access's failed attempts at rendering it in design view)
0
 

Author Closing Comment

by:pdvsa
ID: 39758457
Thank you!  Good night....:)
0

Featured Post

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

Suggested Solutions

Experts-Exchange is a great place to come for help with solutions for your database issues, and many problems are resolved within minutes of being posted.  Others take a little more time and effort and often providing a sample database is very helpf…
A simple tool to export all objects of two Access files as text and compare it with Meld, a free diff tool.
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.
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…

813 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now