DECLARE @pmk_id CHAR(10)

DECLARE list_cursor CURSOR FAST_FORWARD FOR
SELECT PMK_ID FROM SPG_PMK WHERE LEFT(KD_UNIT_ORG_BARU, 3) = '107' AND TGL_MULAI >= '2023-03-01' 

OPEN list_cursor  
FETCH NEXT FROM list_cursor INTO @pmk_id  

WHILE @@FETCH_STATUS = 0  
BEGIN  

	---- update PMK --
	UPDATE
		SPG_PMK
	SET
		KD_UNIT_ORG_BARU = '000' + RIGHT(KD_UNIT_ORG, 21)
	WHERE
		PMK_ID = @pmk_id

	---- update Riwayat Jabatan --
	UPDATE
		SPG_08_RIWAYAT_JABATAN
	SET
		KD_UNIT_ORG = '000' + RIGHT(KD_UNIT_ORG, 21)
	WHERE
		KSO_KASUSNOMOR = @pmk_id
		

	FETCH NEXT FROM list_cursor INTO @pmk_id  
END  

CLOSE list_cursor  
DEALLOCATE list_cursor 