DECLARE	@ENTITY_ID INTEGER,@USER_ID INTEGER
	
	DECLARE c_USER CURSOR FOR
	 SELECT T.USER_ID, T1.FORM_ID FROM  TBPMO_CONSTRUCTOR_USER T, VWPMO_CONSTRUCTOR_FORMS T1 WHERE T.CONSTRUCT_ID = T1.CONSTRUCT_ID AND T1.DOCUMENT_VIEW = 1
		
	OPEN c_USER 
		FETCH NEXT FROM c_USER INTO @USER_ID,@ENTITY_ID
    WHILE @@FETCH_STATUS = 0
		BEGIN
			IF NOT EXISTS(SELECT GUID FROM TBPMO_RIGHT_USER WHERE USER_ID = @USER_ID AND ENTITY_ID =  @ENTITY_ID)
				INSERT INTO TBPMO_RIGHT_USER (USER_ID, ENTITY_ID) VALUES (@USER_ID,@ENTITY_ID)
					
			FETCH NEXT FROM c_USER INTO @USER_ID,@ENTITY_ID
		END
	CLOSE c_USER
	DEALLOCATE c_USER


