I have the following query:
select p.ID,
Received = (select Rec
from Exp
where EstAmt = (select MAX(ex.EstAmt)
from Exp ex
where ex.Prot = p.ID
and EstAmt > 0)
)
From Prot
where Received = 1
In the above, Received is a field I created as an alias that will get the value of what Rec is. Rec is a field in the table.
But when I put Received in the where clause I get: Invalid Column Name ‘Received’. As mentioned, Received is not a field in the table but a place hold er that gets the value from the subquery. Any idea on how i can have Received in the where clause as I need to show the result only if that value is 1.
You would have to filter the results of your original query, using it as a sub query: