You can modify your code as shown in red below:with cte as(Select t.loginid as AgentID, Count(c.CallID) as Opened, c.recvddate as DateFrom Tracker as tInner Join CallLog as con t.loginid = c.recvdbyWhere t.SecGroup in ('GroupA','GroupB')and c.recvddate = CAST(DATEPART(year, GETDATE()) AS char(4)) + '-' + RIGHT('00' + CAST(DATEPART(month, GETDATE()) AS varchar(2)), 2) + '-' + RIGHT('00' + CAST(DATEPART(day, GETDATE()) AS varchar(2)), 2) (I know this is rather crazy but the source date format is text, not DATETIME so I have to convert.)Group by t.loginid, c.recvddate)UPDATE a SET Opened = b.OpenedFROM DatabaseA.dbo.TableA a INNER JOIN CTE b ON a.AgentId = b.AgentId AND a.Date = b.Date;I obviously don't have your tables and data, so I have not tested the code. So before you do anything for real, please test.