I have the following query:
SELECT PROGID1 = P.Prog, ENTERDATE1 = MAX(ENTERDATE),
BANKID = (select B.BANKID from BANK B
WHERE B.ID = PROGID1 and B.ENTERDATE = ENTERDATE1
)
FROM PROTOCOL P JOIN BANK B ON P.ID = B.ID
group by P.ID
What I need to do is to get the BANKID for a given MAX(ENTERDATE) but as BANKID has duplicate records, I need to find it based on what the MAX ENTERDATE
was. I tried to do the following but I get a message saying invalid column name PROGID1 and ENTERDATE1 inside of:
(select B.BANKID from BANK B
WHERE B.ID = PROGID1 and B.ENTERDATE = ENTERDATE1
)
Something like this? I.e., use the “protocol” query as a table.
P.S. I think you used “p.prog” where you meant p.id.