声明@nAlertUID小数(18岁,0);声明@nContactUID小数(18岁,0);声明@nAlertRecipientUID小数(18岁,0);设置@nAlertUID =(选择strAlertUID);如果@nAlertUID不是零开始,删除现有的接受者。更新AlertRecipients组lDeleted = 1, nAlertUID = @nAlertUID;——声明游标。——定义select语句声明Contact_Cursor光标。从FacilityContactLink lDeleted = 0和选择不同nContactUID lActive < > 0,遍历结果。从Contact_Cursor成@nContactUID开放Contact_Cursor取下; WHILE @@FETCH_STATUS = 0 BEGIN -- Check if we have a record we can just 're-activate'. IF (SELECT COUNT(*) FROM AlertRecipients WHERE nAlertUID=@nAlertUID AND nContactUID=@nContactUID) > 0 BEGIN -- Get the first UID SET @nAlertRecipientUID = (SELECT TOP 1 nAlertRecipientUID FROM AlertRecipients WHERE nAlertUID=@nAlertUID AND nContactUID=@nContactUID); UPDATE AlertRecipients SET lActive=-1, lDeleted=0 WHERE nContactUID=@nContactUID AND nAlertUID=@nAlertUID AND nAlertRecipientUID=@nAlertRecipientUID; END ELSE BEGIN -- Inserting a new record. EXEC spl_AlertRecipients_INSERT @nContactUID, @nAlertUID, 'TO' END FETCH NEXT FROM Contact_Cursor INTO @nContactUID END CLOSE Contact_Cursor; DEALLOCATE Contact_Cursor; END ELSE BEGIN print 'The recall report does not exist.' END