I’m trying to use the following code:
m_Set.ClearQueryInfo();
m_Set.SetParameterWhere("PatID = @PatIDParam AND EffectiveEnrollmentDate IN (Select MAX(EffectiveEnrollmentDate))");
m_Set.SetWhere("PatID = ? AND EffectiveEnrollmentDate IN (Select MAX(EffectiveEnrollmentDate))");
m_Set.SetNumParams(1);
m_Set.SetParam("@PatIDParam", 1, PatIDParam.ToString());
but I end up receiving the following error:
An aggregate may not appear in the
WHERE clause unless it is in a
subquery contained in a HAVING clause
or a select list, and the column being
aggregated is an outer reference,
SELECT dbo.[PatRoster].* FROM
dbo.[PatRoster] WHERE PatID =
@PatIDParam AND
EffectiveEnrollmentDate IN (Select
MAX(EffectiveEnrollmentDate))
Your query is not valid –
Select MAX(EffectiveEnrollmentDate)is not complete; it has to selectEffectiveEnrollmentDatefrom somewhere in that subquery.Also,
MAX()only ever returns a single value, so there is no need forIN– you can just do straight comparison operator=.