I have the following query:
Now lets say If the same tax form was added 3 times at different times in a year, If use the above query it will show me 3 rows of data with different EW.TFDate but I want to eliminate the redundant data and tried the following:
But this throws the following error in SQL:
How can I fix this, Please help.
Code:
Create Procedure Emp_Data
@ID varchar(10)
AS
select distinct Emp.ID, Emp.Employee_Name,Emp.Job_Status,
EA.Employee_Address, EA.UpdatedAddress, EA.Update_Time, EW.TaxForms, EW.TFDate
from Employee Emp
left JOIN EmployeeAddress EA
ON EA.ID = Emp.ID
left JOIN EmployeeW2 EW
ON EW.ID = Emp.ID
where ID = @ID
group by Emp.ID, Emp.Employee_Name,Emp.Job_Status,
EA.Employee_Address, EA.Update_Status, EA.Update_Time, EW.TaxForms, EW.TFDate
Now lets say If the same tax form was added 3 times at different times in a year, If use the above query it will show me 3 rows of data with different EW.TFDate but I want to eliminate the redundant data and tried the following:
Code:
Create Procedure Emp_Data
@ID varchar(10)
AS
select distinct Emp.ID, Emp.Employee_Name,Emp.Job_Status,
EA.Employee_Address, EA.UpdatedAddress, EA.Update_Time, EW.TaxForms, EW.TFDate
from Employee Emp
left JOIN EmployeeAddress EA
ON EA.ID = Emp.ID
left JOIN EmployeeW2 EW
ON EW.ID = Emp.ID
where ID = @ID
group by EW.TaxForms
Code:
Msg 8120, Level 16, State 1, Emp_Data,
Column 'Emp.ID' is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause.
How can I fix this, Please help.