SET NOCOUNT ON
DECLARE @FK_DepartmentNumber INT
DECLARE @UserIdNumber INT
DECLARE @AreaFunctionNumber INT

DECLARE @SystemUserIDNumber INT
SELECT TOP 1 @SystemUserIDNumber = UserIdNumber FROM Personel WITH (NOLOCK) WHERE UserTypeNumber = 2

DECLARE db_user CURSOR FOR
  SELECT UserIdNumber FROM Personel WITH (NOLOCK)
OPEN db_user

FETCH NEXT FROM db_user INTO @UserIdNumber

WHILE @@FETCH_STATUS = 0
BEGIN
  IF NOT EXISTS(SELECT * FROM PersonelAccess WITH (NOLOCK) WHERE UserIdNumber = @UserIdNumber AND AreaNumber = 4 AND AreaFunctionNumber = 30)
  BEGIN
    IF @SystemUserIDNumber = @UserIdNumber
      INSERT INTO PersonelAccess (UserIdNumber, AreaFunctionNumber, Access, AreaNumber) VALUES (@UserIdNumber, 30, 1, 4)
    ELSE
      INSERT INTO PersonelAccess (UserIdNumber, AreaFunctionNumber, Access, AreaNumber) VALUES (@UserIdNumber, 30, 0, 4)
  END
  FETCH NEXT FROM db_user INTO @UserIdNumber
END  

CLOSE db_user
DEALLOCATE db_user