Last post Sep 03, 2018 08:13 PM by Stoian Bucovich
Sep 03, 2018 08:02 PM|Stoian Bucovich|LINK
I am having and issue with query I am trying to run any help would be greatly appreciated. So here is the query:
Declare @FromDate datetime = '2018-01-01';
Declare @ToDate datetime = '2018-12-12';
Select u.RealName, r.Marketing, u.Email, (Select EntityName From dbo.Entities Where ID = r.EntityID) As Entity From dbo.Reservations As r Inner Join dbo.Users As u On u.ID = r.Marketing Where r.TripDate >= @FromDate And r.TripDate <= @ToDate And r.Canceled
= 0 Group By r.Marketing;
What I am trying to do is to get the totals Count(*) of reservations by User Where Marketing is the User's ID from the Users table and grouped by User ID but distinct by EntityID.
The error I am getting: Column 'dbo.Users.RealName' is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause.
Sep 03, 2018 08:13 PM|Stoian Bucovich|LINK
Anyhow I've figured it out myself with small modification. Here it is anyway hopefully could help someone else.
Select Count(*) As Totals, u.RealName, r.Marketing, u.Email From dbo.Reservations As r Inner Join dbo.Users As u On u.ID = r.Marketing
Where r.TripDate >= @FromDate And r.TripDate <= @ToDate And r.Canceled = 0 Group By r.Marketing, u.RealName, u.Email Order By RealName;