Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2012 Forums
 SQL Server Administration (2012)
 SQL error 8120

Author  Topic 

syedasadali1986
Starting Member

1 Post

Posted - 2015-04-10 : 11:18:19
Dears, I want to know how to add GROUP BY DateTime in below query,

select RouterCallKey, DateTime, ANI, DNIS, DigitsDialed, AgentPeripheralNumber,InstrumentPortNumber,Duration, TalkTime, Variable1, Variable2, Variable6, Variable9, Variable10, CallDisposition, SkillGroupSkillTargetID
from t_Termination_Call_Detail
where DateTime >='2015-04-08 00:00'
and DateTime <= '2015-04-08 23:59'
--and SkillGroupSkillTargetID in ('6537','6547','10760','15866','17894','17967')
and SkillGroupSkillTargetID in ('17965','17967')
and AgentPeripheralNumber !=''
and InstrumentPortNumber !=''
and TalkTime > 0
GROUP BY DateTime



When i was run the query they given the error ''Msg 8120, Level 16, State 1, Line 1Column 't_Termination_Call_Detail.RouterCallKey' is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause''



Appricate your input

asad

James K
Master Smack Fu Yak Hacker

3873 Posts

Posted - 2015-04-10 : 11:40:12
The general rule when using GROUP BY is that any column in the SELECT list that is not in the GROUP BY list must be an aggregate. So if you want to group by the DateTime column, every other column in your select list - RouterCallKey, ANI etc... must be in an aggregate function. Eg. MAX(RouterCallKey), and so on.

What is the logic you are trying to implement? Why the group by on Datetime column? If you can describe the problem you are trying to solve, someone should be able point you in the right direction.

By the way, I would discourage you from using column names that are also keywords or reserved words in SQL Server. Datetime for example.
Go to Top of Page
   

- Advertisement -