You can use a CTE (Common Table Expression) to find the last activity for each customer:
;WITH LastActivity AS
(
SELECT
CustomerID, ActivityID, CreatedOnDate,
ROW_NUMBER() OVER(PARTITION BY CustomerId ORDER BY CreatedOnDate DESC) 'RowNum'
FROM
dbo.CustomerActivity
)
SELECT * FROM LastActivity
WHERE RowNum = 1
This will give you one row for each customer with the activity that has the latest date. The PARTITION BY
partitions your data by customer, e.g. the counter starts at 1 again for each new customer. The ORDER BY
defines the descending ordering by date, so that the latest/newest activity is the first one, with row number 1.
Now you can use the CTE to update your other table:
;WITH LastActivity AS
(
SELECT
CustomerID, ActivityID, CreatedOnDate,
ROW_NUMBER() OVER(PARTITION BY CustomerId ORDER BY CreatedOnDate DESC) 'RowNum'
FROM
dbo.CustomerActivity
)
UPDATE dbo.TempUpdateTable
SET RecentActivityDate = act.CreatedOnDate
FROM LastActivity act
WHERE dbo.TempUpdateTable.CustomerId = act.CustomerID
AND act.RowNum = 1