我正在尝试使用以下代码:
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());
但我最终收到以下错误:
聚合可能不会出现在WHERE子句中,除非它在HAVING子句或选择列表中包含的子查询中,并且正在聚合的列是外部引用SELECT dbo。[PatRoster]。* FROM dbo。[PatRoster] WHERE PatID = @PatIDParam和EffectiveEnrollmentDate IN(选择MAX(EffectiveEnrollmentDate))
您的查询无效-SelectMAX(EffectiveEnrollmentDate)不完整;它必须EffectiveEnrollmentDate从该子查询中的某个位置进行选择。
SelectMAX(EffectiveEnrollmentDate)
EffectiveEnrollmentDate
另外,MAX()只返回一个值,因此没有必要IN-您可以执行直接比较操作符=。
MAX()
IN
=