Kim:
You don't need a Trans_In_Out column in the Print Table. If you look at the
SQL statement:
SELECT Print_ID, Title, Author,
IIF(EXISTS
(SELECT *
FROM LendTransactions
WHERE LendTransactions.Print_ID = [Print Table].Print_ID
AND NOT Trans_In_Out), "Unavailable", "Available")
FROM [Print Table]
ORDER BY Title, Author;
You'll see that the reference to the Trans_In_Out column is in a subquery
with the LendTransactions table in its FROM clause. What the query is saying
is:
"Give me the Print_ID, Title and Author columns from the Print Table and,if
there exists a row in the LendTransactions table where the value of the
Print_ID column in any row in the LendTransactions table equals the valueof
the Print_ID column in a row in the current row of the Print Table and the
value of the Trans_In_Out column is False, say "Unavailable", otherwise say
"Available".
The subquery here is what's known as a 'correlated subquery' because it is
correlated with the outer query (which is based on the Print Table). The
subquery in effect runs separately for every row returned by the outer query.
If it returns any rows then the EXISTS predicate is True, if not its False.
The IIF function then returns "Unavailable" or "Available" on the basis of
whatever the EXISTS predicate has evaluated to for the current row returned
by the outer query, i.e. for each book.
Don't forget that I've assumed that if Trans_In_Out is False (No) that means
a book is currently lent out. If I've got this the wrong way round just
delete the NOT before Trans_In_Out.
Ken Sheridan
Stafford, England
Thanks Ken. I'm a bit confused with the first option; as I don't have
a Field Name of Trans_In_Out on Print_ID table. I have this on my
LendTransactions table. I put this on the LendTransaction table, but
I'm still seeing the list of titles when they're inactive.- Hide quotedtext -
- Show quoted text -