SO i've been working on a series of sql commands / reports. I'm trying to get the SUM of total incidents that a particular individual creates then keeps adding to daily if incidents occur. So if Tim gets an incident 1 day, then 0 the next, then 2 the following day, it'll show his name next to 3 incidents.
Example: TableA
Tim | 1 | day one
Tim | 0 | day two
Tim | 2 | day three
TableB
Tim | 3 | week1
Here are some SQL commands I've tried:
INSERT INTO WeeklyReport(ImportDate, DayofData, [Name], TotalA, TotalB, TotalC)
SELECT GETDATE() AS ImportDate, DATEADD(day, -1, GETDATE()) AS DayofData, p.[Name], SUM(p.IncidentA), SUM(c.IncidentB), SUM(n.IncidentC)
FROM TableA p
INNER JOIN TableB c ON c.[Name] = p.[Name]
INNER JOIN TableC n ON n.[Name] = p.[Name]
I run into this error:
Msg 8120, Level 16, State 1, Line 2 Column 'TableA.Name' is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause.
What changes can be made to the command to better accommodate this error?