Solved

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

Posted on 2014-09-25
4
202 Views
Last Modified: 2014-09-25
I get an error on the following query.  What seems to be the problem?

DECLARE @fromdt AS datetime 
DECLARE @todt AS datetime
SET @fromdt = '7/1/2014'
SET @todt = '7/31/2014'
select * from tblOrgRegistrations as r 
JOIN tblOrgHours as h
 ON h.RegID = r.regid
 Where r.AgencyID = 74 And (h.ActivityDate >= @fromdt And h.ActivityDate <= @todt)
 Group By r.Agency

Open in new window


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

Open in new window

0
Comment
Question by:al4629740
  • 2
4 Comments
 
LVL 69

Assisted Solution

by:Scott Pletcher
Scott Pletcher earned 250 total points
ID: 40344486
Remove the GROUP BY; I don't think you need it for this query.
0
 
LVL 75

Accepted Solution

by:
Aneesh Retnakaran earned 250 total points
ID: 40344491
I think you put GROUP BY instead of ORDER BY
0
 

Author Comment

by:al4629740
ID: 40344494
got it
0
 

Author Closing Comment

by:al4629740
ID: 40344495
it was suppose to be order by
0

Featured Post

Guide to Performance: Optimization & Monitoring

Nowadays, monitoring is a mixture of tools, systems, and codes—making it a very complex process. And with this complexity, comes variables for failure. Get DZone’s new Guide to Performance to learn how to proactively find these variables and solve them before a disruption occurs.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

JSON is being used more and more, besides XML, and you surely wanted to parse the data out into SQL instead of doing it in some Javascript. The below function in SQL Server can do the job for you, returning a quick table with the parsed data.
Ever needed a SQL 2008 Database replicated/mirrored/log shipped on another server but you can't take the downtime inflicted by initial snapshot or disconnect while T-logs are restored or mirror applied? You can use SQL Server Initialize from Backup…
Via a live example, show how to backup a database, simulate a failure backup the tail of the database transaction log and perform the restore.
Via a live example, show how to set up a backup for SQL Server using a Maintenance Plan and how to schedule the job into SQL Server Agent.

726 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question