Hi,I am trying to write a stored procedure that returns a table with four columns:Col 1 - A list of all the EmployerID values in the employers table (EmployerID is the primary key for the employers table).Col 2 - The EmployerName value from the employers table that matches the EmployerID in Col 1Col 3 - The most recent DateReceived value (if one exists) from the reports table where:a. reports.EmployerID matches the EmployerID in Col 1 of the returned results;b. reports.ReportType matches 'Report Type Q'; andc. reports.ReportPeriod value is equal to the @ReportPeriod input parameter.Col 4 - Same as Col 3 except the reports.ReportType value needs to match 'Report Type D'When I execute the code provided below, I get the following results:EmployerID------EmployerName-------QR-------------Dues 1000------------Employer A----------2008-07-01-----2008-07-02 1001------------Employer B----------2008-07-01-----2008-07-02 However, the desired results are:EmployerID------EmployerName-------QR-------------Dues 1000------------Employer A----------2008-07-01----2008-07-02 1001------------Employer B----------2008-07-01 1002------------Employer C-------------------------2008-07-02 Here is the code. Any suggestions are much appreciated!!use tempdb;CREATE TABLE Employers(EmployerID int PRIMARY KEY,EmployerName varchar(50))INSERT INTO Employers (EmployerID, EmployerName)VALUES ('1000', 'Employer A')INSERT INTO Employers (EmployerID, EmployerName)VALUES ('1001', 'Employer B')INSERT INTO Employers (EmployerID, EmployerName)VALUES ('1002', 'Employer C')-- drop table ReportsCREATE TABLE Reports(ReportID int IDENTITY(1,1) PRIMARY KEY,EmployerID int,ReportType varchar(50),DateReceived datetime,ReportPeriod varchar(20))INSERT INTO Reports (EmployerID,ReportType,DateReceived,ReportPeriod)VALUES ('1000','Report Type Q','7/1/2008','June / Q2 2008')INSERT INTO Reports (EmployerID,ReportType,DateReceived,ReportPeriod)VALUES ('1000','Report Type D','7/2/2008','June / Q2 2008')INSERT INTO Reports (EmployerID,ReportType,DateReceived,ReportPeriod)VALUES ('1001','Report Type Q','7/1/2008','June / Q2 2008')INSERT INTO Reports (EmployerID,ReportType,DateReceived,ReportPeriod)VALUES ('1002','Report Type D','7/2/2008','June / Q2 2008')GOCREATE PROCEDURE GetMonthlySummary@ReportPeriod varchar(20)ASSELECT e.EmployerID,e.EmployerName, MAX(q.DateReceived) AS QR, MAX(d.DateReceived) AS Dues-- select *FROM employers eLEFT JOIN (Select * FROM reports WHERE reports.ReportType='Report Type Q') qON q.EmployerID=e.EmployerIDAND q.ReportPeriod=@ReportPeriodJOIN(Select * FROM reports WHERE reports.ReportType='Report Type D') As dON q.EmployerID=e.EmployerID AND q.ReportPeriod=@ReportPeriodGROUP BY e.EmployerID,e.EmployerNameGOexec GetMonthlySummary 'June / Q2 2008'GO