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
 General SQL Server Forums
 New to SQL Server Programming
 report

Author  Topic 

tariq2
Posting Yak Master

125 Posts

Posted - 2011-02-22 : 11:24:17

-- So the following query gives me a list of users and the number of
times they have used different reports

select UserName,ReportName,ReportCount from View_BIUsers_ReportData
where LEID = '02001' and SBLID = 'MKG'
and TreeYear = 2011
and Year = 2011

---- I want to now group this by username and try the following

select UserName,ReportName,sum(ReportCount) from View_BIUsers_ReportData
where LEID = '02001' and SBLID = 'MKG'
and TreeYear = 2011
and Year = 2011
group by ReportName

and get the following message:

Msg 8120, Level 16, State 1, Line 1
Column 'View_BIUsers_ReportData.UserName' is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause.

So When I try MAX(username) it obviously gives me the user
who has used teh report the maximum number of times
which is not what I want.

Any help is much appreciated



tariq2
Posting Yak Master

125 Posts

Posted - 2011-02-22 : 11:55:37
I have realized what was wrong. Thanks
Go to Top of Page
   

- Advertisement -