USE ManageSoft
GO

ALTER PROCEDURE ResourcesDeleteByLanguageID
       @LanguageID                nvarchar(6)
AS BEGIN

       DELETE        SecurityPatchResource 
       FROM        SecurityPatchResource as spr,
               SecurityPatch as sp
       WHERE        sp.PatchID = spr.SecurityPatchID
        AND        spr.LanguageID = @LanguageID
        AND        (
                sp.State = 1 OR
                spr.Incorporate = 0
               )

       DELETE SecurityPatch
       WHERE NOT EXISTS (
               SELECT SecurityPatchID FROM SecurityPatchResource 
               WHERE SecurityPatchID = SecurityPatch.PatchID
       )
       AND BulletinID <> 'Unknown'
       
END
GO