UPDATE Notifications SET IsProcessed = 0
WHERE ID IN
(
select Z.ID FROM old_InstancesTable OI 
inner join (select ID, CAST(SUBSTRING(MetaData, CHARINDEX('<DocId>', MetaData) + 7, CHARINDEX('</DocId>', MetaData) - CHARINDEX('<DocId>', MetaData) -7) AS INT) DOCID  from old_Notifications) Z
ON OI.DWDocumentID = Z.DOCID
WHERE OI.ExecutionStatus<>'Closed'
)