Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
197 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

Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

Question has a verified solution.

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

Suggested Solutions

This article shows gives you an overview on SQL Server 2016 row level security. You will also get to know the usages of row-level-security and how it works
In this article we will learn how to fix  “Cannot install SQL Server 2014 Service Pack 2: Unable to install windows installer msi file” error ?
Via a live example, show how to extract information from SQL Server on Database, Connection and Server properties
Viewers will learn how to use the UPDATE and DELETE statements to change or remove existing data from their tables. Make a table: Update a specific column given a specific row using the UPDATE statement: Remove a set of values using the DELETE s…

809 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