--SELECT * FROM dbo.SPG_JNS_ABSENSI WHERE KD_ABSENSI IN ('PT', 'PS', 'PN')

DECLARE
	@dari DATE = '2019-11-01',
	@sampai DATE = '2019-12-28'
SELECT
	sra.NIP,
	sdc.NM_PEG,
	CAST(CAST(sra.TANGGAL_ABSEN AS VARCHAR(8)) AS DATE) AS TANGGAL_ABSEN,
	sra.TIPE,
	sja.KETERANGAN
FROM
	dbo.SPG_REPORT_ABSENSI AS sra INNER JOIN
	dbo.SPG_DATA_CURRENT AS sdc ON sra.NIP = sdc.NIP LEFT JOIN
	dbo.SPG_JNS_ABSENSI AS sja ON sra.TIPE = CAST(sja.ID AS VARCHAR(2))
WHERE
	(
		sra.TIPE LIKE '%48%'
		OR sra.TIPE LIKE '%49%'
		OR sra.TIPE LIKE '%50%'
	)
	AND CAST(CAST(sra.TANGGAL_ABSEN AS VARCHAR(8)) AS DATE) >= @dari
	AND CAST(CAST(sra.TANGGAL_ABSEN AS VARCHAR(8)) AS DATE) <= @sampai
ORDER BY
	sra.TANGGAL_ABSEN,
	sdc.NM_PEG
