DECLARE
	@dari DATE = '2021-01-02',
	@sampai DATE = '2021-03-29'

-- buat tabel temporary
DECLARE @hasil TABLE ( 
					ID INT,
					NIP VARCHAR(32),
					NM_PEG VARCHAR(100),
					KD_UNIT_ORG VARCHAR(50),
					CREATE_DATE DATE
				)

-- posisi data looping diset awal berupa tanggal @dari
DECLARE @current_date DATE = @dari

WHILE (@current_date <= @sampai)
	BEGIN
		INSERT INTO @hasil (ID, NIP, NM_PEG, KD_UNIT_ORG, CREATE_DATE)
		SELECT 
			ID, NIP, NM_PEG, KD_UNIT_ORG, CREATE_DATE
		FROM 
			mart_profile_pegawai 
		WHERE 
			STS_PENSIUN = 0 
			AND CREATE_DATE = @current_date
			AND NIP NOT IN (
							SELECT 
								NIP 
							FROM 
								mart_profile_pegawai 
							WHERE 
								CREATE_DATE = DATEADD(DAY, 1, @current_date)
								AND STS_PENSIUN = 0
						)

		-- next hari berikutnya
		SET @current_date = DATEADD(DAY, 1, @current_date)
	END

-- tampilkan hasilnya
SELECT 
	* 
FROM 
	@hasil
ORDER BY
	CREATE_DATE,
	NIP