Solved

2 queries, 1 checks other for matching field and returns "yes"

Posted on 2013-02-04
5
129 Views
Last Modified: 2013-02-04
I have two access queries.

Query 1: List of peoples names plus a reference number.
Query 2: A list of reference numbers.

In query 1 i'd like to add another column that simply returns Yes and No.
Yes if the reference number matches any reference number in Query 2.
No if no match is found.

How do I do this?
0
Comment
Question by:antonioking
5 Comments
 
LVL 22

Expert Comment

by:plusone3055
ID: 38850952
Use an UPDATE statement
0
 
LVL 61

Accepted Solution

by:
mbizup earned 500 total points
ID: 38850964
Try this:

SELECT q1.*,  IIF(q2.RefNumber IS NULL, "NO", "YES" ) AS RefInQuery2
FROM Query1 q1 LEFT JOIN Query2 q2 ON q1.RefNumber = q2.RefNumber

Open in new window

0
 
LVL 77

Expert Comment

by:peter57r
ID: 38850973
Your version of....

SELECT query1.*, IIf(IsNull([query2].[reference]),"No","Yes") AS Matched
FROM Query1 LEFT JOIN Query2
ON Query1.Reference = query2.Reference;
0
 
LVL 22

Expert Comment

by:plusone3055
ID: 38850987
First things first you have to run the 2nd query to get all the reference numbers and put them in a dummy table or a temp table

THEN do an update statement on the data table that query 1 is running against

so lets say that query 1 returns data from table1
query 2 returns data from table 2


UPDATE
[table1]
SET
column(yes/no) =
(
CASE
WHEN
(table1.id = table2.id)
'YES'
ELSE
column(yes/no) = NO
END
)
WHERE
table1.id <> NULL
0
 

Author Closing Comment

by:antonioking
ID: 38851266
Perfect, thanks!
0

Featured Post

Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

Question has a verified solution.

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

QuickBooks® has a great invoice interface that we were happy with for a while but that changed in 2001 through no fault of Intuit®. Our industry's unit names are dictated by RUS: the Rural Utilities Services division of USDA. Contracts contain un…
I originally created this report in Crystal Reports 2008 where there is an option to underlay sections. I initially came across the problem in Access Reports where I was unable to run my border lines down through the entire page as I was using the P…
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …

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