0

Hello I am trying to execute the following query in MSSQL and for some reason I cant get the DateTime column when I use MAX(MaxNumberLoggedOnAgentsToHalf) in my select statement. it complains :

Column 'Peripheral_Half_Hour.DateTime' is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause.

Can anyone assist? Here is my select statement:

SELECT EnterpriseName, MAX(MaxNumberLoggedOnAgentsToHalf) Max_Agents, DateTime
FROM Peripheral_Half_Hour PHH, Peripheral P 
WHERE PHH.PeripheralID = P.PeripheralID  AND MaxNumberLoggedOnAgentsToHalf > 0
GROUP BY EnterpriseName

Thanks!

pconcepcion
  • 5,591
  • 5
  • 35
  • 53

1 Answers1

0

Add each column in your SELECT clause to a new GROUP BY clause for all of the non-derived columns in your SELECT:

SELECT a.col1
  ,a.col2
  ,a.col3
FROM [SomeTable$] a
WHERE whatever
GROUP BY a.col1
  ,a.col2
  ,a.col3
Bill
  • 5
  • 3