sql server 2008 - Group By in stored procedure error -
i created stored procedure return list of offices type of activities happen within each office. results reported reportviewer noticed each activity return creates table - can have 5 different tables each own activity happen in same office. want report table each office contain many activites there each office. thought if grouped in stored procedure results want getting column error saying: "...is invalid in select list because not contained in either aggregate function or group clause."
i not sure how go here select, from, where, group statements:
select o.officeid, o.officename office, ht.description hearingtype, h.hearingdate hearingdate, cr.description court, ct.[description]as casetype activity h inner join activityentry on h.activityentryid = he.activityentryid inner join activitytype ht on h.activitytypeid = ht.activitytypeid inner join [case] c on h.caseid = c.caseid inner join [office] o on he.createdbyofficeid = o.officeid inner join [user] u on c.createdbyuserid = u.userid left outer join casetype ct on c.casetypeid = ct.casetypeid left outer join court cr on c.courtid = cr.courtid .dbo.dateonly(he.hearingdate)between @begindate , @enddate group o.officeid, o.officename, ht.description order o.officeid, ht.description
group by
requires have kind of aggregate function in list of columns - sum
, avg
, count
. group by
makes sense in combination aggregate.
otherwise, order data order by
statement.
Comments
Post a Comment