Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Referring to Calculated Fields in a Select Query. 1

Status
Not open for further replies.

BNPMike

Technical User
Sep 17, 2001
1,818
GB
This query works:

SELECT MAS.[CAC-BUY-TO-LET-IND] AS Mval, Summit.[CAC-BUY-TO-LET-IND]
FROM MAS LEFT JOIN Summit ON MAS.[CAC-LOAN-ID] = Summit.[CAC-LOAN-ID];

However when I try to compare the two fields Access doesn't understand; it asks for a parameter value:

SELECT MAS.[CAC-BUY-TO-LET-IND] AS Mval, Summit.[CAC-BUY-TO-LET-IND]
FROM MAS LEFT JOIN Summit ON MAS.[CAC-LOAN-ID] = Summit.[CAC-LOAN-ID]
WHERE (((Summit.[CAC-BUY-TO-LET-IND])=[Mval]));

This is basic but just can't remember how you do it and I can't see anything in Access 2003 Inside Out.

 
Try
Code:
SELECT MAS.[CAC-BUY-TO-LET-IND] AS Mval, Summit.[CAC-BUY-TO-LET-IND]
FROM MAS LEFT JOIN Summit ON MAS.[CAC-LOAN-ID] = Summit.[CAC-LOAN-ID]
WHERE (((Summit.[CAC-BUY-TO-LET-IND])= [red]MAS.[CAC-BUY-TO-LET-IND][/red] ));
although, since you are doing a JOIN anyway
Code:
SELECT MAS.[CAC-BUY-TO-LET-IND] AS Mval, Summit.[CAC-BUY-TO-LET-IND]

FROM MAS LEFT JOIN Summit 

ON MAS.[CAC-LOAN-ID] = Summit.[CAC-LOAN-ID]
   AND Summit.[CAC-BUY-TO-LET-IND] = MAS.[CAC-BUY-TO-LET-IND]

SQL evaluates clauses in approximately this order

FROM
WHERE
GROUP BY
ORDER BY
SELECT

so it doesn't know that [Mval] is a field alias when it is evaluating the WHERE clause.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top