Hi everyone,Sorry to post this question again since it was answered last week, but I changed my query a bit and I'm having the same issue again.My query seems to be counting records a lot more than once since I'm using an inner join. The query results are inaccurate and I can't figure it out since I don't use SQL much.On The dbCreditData.dbo.tbl_pt_Completed table there are multiple records for each associate id on each day because they create a record for each SubFunction_ID. On the dbCreditData.dbo.vw_Credit_ProdData table there is only one record per associate id.QuerySELECT Prod.Dtdate as Date ,Prod.iAssociateID as ID ,Comp.Name ,sum(case when Comp.SubFunction_ID = 1 then Comp.Completed else 0 end) as SF1 ,sum(case when Comp.SubFunction_ID = 2 then Comp.Completed else 0 end) as SF2 ,sum(case when Comp.SubFunction_ID = 3 then Comp.Completed else 0 end) as SF3 ,sum(case when Comp.SubFunction_ID = 4 then Comp.Completed else 0 end) as SF4 ,sum(case when Comp.SubFunction_ID = 5 then Comp.Completed else 0 end) as SF5 ,Prod.iCallsAnswered as Calls ,Prod.iTIASeconds as TIA ,Prod.iNPPSeconds as NPP ,Prod.iBreakSeconds as BreaksFROM [dbCreditData].[dbo].[vw_Credit_ProdData] ProdINNER JOIN (SELECT AssocID, Name, MainFunction_ID, SubFunction_ID, Completed, UserID FROM [dbCreditData].[dbo].[tbl_pt_Completed] GROUP BY AssocID, Name, MainFunction_ID, SubFunction_ID, Completed, UserID) Comp ON Prod.iAssociateID = Comp.AssocIDWHERE Prod.dtDate Between '05/10/10' and '05/11/10' and Prod.iTIASeconds > 0 and MainFunction_id = 1 and Comp.UserID = 20GROUP by Prod.dtdate ,Prod.iAssociateID ,Prod.iCallsAnswered ,Prod.iNPPSeconds ,Prod.iTIASeconds ,Prod.iBreakSeconds ,Prod.iCTCompleted ,Comp.NameORDER by Prod.dtDate ,Comp.Name
Query ResultsDate ID Name SF1 SF2 SF3 SF4 SF5 Calls TIA NPP Breaks2010-05-10 91000000 Blah 1593 0 58 14 717 34 29160 0 18002010-05-11 91000000 Blah 1593 0 58 14 717 19 28980 0 1800
Expected ResultsDate ID Name SF1 SF2 SF3 SF4 SF5 Calls TIA NPP Breaks2010-05-10 91000000 Blah 143 0 4 4 54 34 29160 0 18002010-05-11 91000000 Blah 92 0 7 7 45 19 28980 0 1800
I'm using T SQL on Microsoft SQL Server Management Studio 2008