UPDATE @tmpContacts
SET NumContactsMade = b.Contacts FROM
(
SELECT ClientID, SUM(Contacts) AS Contacts
FROM
(
SELECT ClientID, COUNT(Client_Contact_Tbl.ClientID) AS Contacts
FROM Client_Contact_Tbl
GROUP BY ClientID, Contact_Status, ContactDate
HAVING Contact_Status IS NOT NULL AND ContactDate >= '6/20/2010'
) a
GROUP BY a.ClientID
) b, @tmpContacts
|