Possible Duplicate:
sql server use computed column
Is there a way to do this:
select Name,
(SELECT Max(reference)
from Rematch
WHERE Gender='M' and convert(varchar,getdate,103) = '08/10/2012'
) As MaxReferenceMale,
(SELECT Max(reference)
from Rematch
WHERE Gender='F' and convert(varchar,getdate,103) = '08/10/2012'
) As MaxReferenceFemale
WHERE (Gender='M' and Reference > MaxReferenceMale) Or
(Gender='F' and Reference > MaxReferenceFemale)
I realise there may be better ways of writing the query. Is it possible to refer to MaxReferenceFemale and MaxReferenceMale in the WHERE clause?
Stick a
around your query. You can use the aliased columns in your WHERE clause once it’s on the inside of the outer SELECT.