 WITH LatestSignature AS (
     SELECT 
         sig.SaveDate,
         sig.Recipe,
         sig.RecipeSignatureID
     FROM 
         [APS].[T_RECIPE_SIGNATURE] sig
     WHERE 
         NOT EXISTS (
             SELECT 1 
             FROM [APS].[T_RECIPE_SIGNATURE]  sig2
             WHERE 
                 sig2.Recipe = sig.Recipe
                 AND sig2.SaveDate > sig.SaveDate
         )
 )
 UPDATE r
 SET 
     r.LastSignature = ls.RecipeSignatureID
 FROM [APS].[T_RECIPE] AS r
 JOIN LatestSignature AS ls ON r.RecipeID = ls.Recipe
 GO
 
 WITH LatestStatusHistory AS (
    SELECT 
        sh.CreationDateTime,
        sh.Recipe,
        sh.RecipeStatusHistoryID
    FROM 
        [APS].[T_RECIPE_STATUS_HISTORY] AS sh
    WHERE 
        NOT EXISTS (
            SELECT 1 
            FROM [APS].[T_RECIPE_STATUS_HISTORY] AS sh2
            WHERE 
                sh.Recipe = sh2.Recipe
                AND sh2.CreationDateTime > sh.CreationDateTime
        )
)    
UPDATE r
SET 
    r.LastStatusHistory = lsh.RecipeStatusHistoryID
FROM [APS].[T_RECIPE] AS r
JOIN LatestStatusHistory AS lsh ON r.RecipeID = lsh.Recipe
GO