I have 2 tables
Table 1:
create table Tb1
(
id int identity(1,1) primary key,
repoted int foreign key references Tb2(id)
)
go
Table 2
create table Tb2
(
id int identity(1,1) primary key,
name nvarchar(100)
)
go
Procedure:
create procedure test
@reported int
as
select
reported, name, count(reported) as numberofreport
from
Tb1
cross join
Tb2
where
reported = @reported
group by
reported
When I execute the query, it returns an error:
Msg 8120, Level 16, State 1, Procedure test, Line 4
Column 'Tb2.name' is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause.
Then I enter edit the group by to reported, name. The error gone but it shows all of my records in the table, only change the name.
Any solution for this problem?