CREATE PROCEDURE [dbo].[sp_Add_PersonId_to_private_report]
@PersonId integer

AS

DECLARE @MyCursor CURSOR;
DECLARE @MyField Integer;
BEGIN
  SET @MyCursor = CURSOR FOR
  SELECT DISTINCT EntityId 
  FROM AccessLevel 
  WHERE EntityTypeCode = 'PRIVATEREPORT'

  OPEN @MyCursor
  FETCH NEXT FROM @MyCursor
  INTO @MyField

  WHILE @@FETCH_STATUS = 0
  BEGIN
    INSERT INTO AccessLevel (EntityId, EntityTypeCode, AccessLevelCode, AccessSubjectCode, AccessGroupId)
	VALUES (@MyField, 'PRIVATEREPORT', 'EDIT', 'PERSON', @PersonId)

	FETCH NEXT FROM @MyCursor
	INTO @MyField
  END;

  CLOSE @MyCursor;
  DEALLOCATE @MyCursor;
END;
