-- G.1--before-while-2-set-initial-proc_with_groups_id
update `CRM_PROCES_idx_TEMP` i
	join `CRM_WSKAZNIK` as wsk on ( wsk.`ID_PROCES`= i.`ID_PROCES`
			and wsk.`A_STATUS` in ( 'NORMAL', 'WAITING' )
		)
	join `CRM_LISTA_ZASOBOW` as z on ( z.`ID` = wsk.`ID_ZASOB`
			and z.`TYPE` in ( 'STANOWISKO', 'PODMIOT', 'DZIAL' )
			and z.`A_STATUS` in ( 'NORMAL', 'WAITING' )
		)
	join `CRM_PRZYPADEK` przyp on ( przyp.`ID` = wsk.`ID_PRZYPADEK`
			and przyp.`FORM_TREAT` & 8 -- has perm X
		)
	set
		i.`idx_PROCES_WITH_GROUPS_ID` = i.`ID_PROCES`
	where i.`idx_PROCES_INIT_ID` > 0
;
