text: UPDATE KWT_PEMBAYARAN_AI 
  SET PERIODE_AIR = CONVERT(VARCHAR(6), DATEADD(MONTH, -1, CAST(PERIODE_TAG + '01' AS DATE)), 112) 
  WHERE TRX IN (1,2,3,4) -- Untuk deposite dan lain-lain periode air dikosongkan
  GO 
  
  INSERT INTO KWT_PELANGGAN 
  (
  	KODE_BLOK,
  	KODE_CLUSTER,
  	KODE_SEKTOR,
  	NO_PELANGGAN,
  	INFO_TAGIHAN,
  	TGL_PPJB,
  	LUAS_KAVLING,
  	LUAS_BANGUNAN,
  	STATUS_BLOK,
  	NAMA_PELANGGAN,
  	NPWP,
  	ALAMAT,
  	NO_TELEPON,
  	NO_HP,
  	SM_NAMA_PELANGGAN,
  	SM_ALAMAT,
  	SM_NO_TELEPON,
  	SM_NO_HP, 
  	KET, 
  	CREATED_DATE,
  	
  	TIPE_IPL,
  	KEY_IPL
  )
  SELECT
  	DISTINCT(a.IUA_CODE) AS KODE_BLOK,
  	a.IUA_CLUSTER_ID AS KODE_CLUSTER,
  	a.IUA_SECTOR_ID AS KODE_SEKTOR,
  	a.IUA_ID AS NO_PELANGGAN,
  	1 AS INFO_TAGIHAN,
  	o.IUAO_PPJB_DATE AS TGL_PPJB,
  	a.IUA_AREA_SQUARE AS LUAS_KAVLING,
  	a.IUA_BUILD_SQUARE AS LUAS_BANGUNAN,
  	9 AS STATUS_BLOK,
  	
  	c.IUC_NAME AS NAMA_PELANGGAN,
  	c.IUC_NPWP AS NPWP,
  	ISNULL(c.IUC_KTP_ADDR, '') + ISNULL(', ' + c.IUC_KTP_TOWN, '') AS ALAMAT,
  	ISNULL(c.IUC_HOME_PHONE, '') + ISNULL(' / ' + c.IUC_OFFICE_PHONE, '') AS NO_TELEPON,
  	c.IUC_CELL_PHONE AS NO_HP,
  	
  	c.IUC_NAME AS SM_NAMA_PELANGGAN,
  	ISNULL(c.IUC_LETTER_ADDR, '') + CASE WHEN c.IUC_LETTER_TOWN IS NULL THEN '' ELSE ', ' + c.IUC_KTP_TOWN END AS SM_ALAMAT,
  	ISNULL(c.IUC_HOME_PHONE, '') + ISNULL(' / ' + c.IUC_OFFICE_PHONE, '') AS SM_NO_TELEPON,
  	c.IUC_CELL_PHONE AS SM_NO_HP, 
  	'BLOK IMPORT' AS KET, 
  	c.IUC_CREATED AS CREATED_DATE,
  	
  	(
  		SELECT TOP 1
  			REPLACE(h.IUAC_CODE, ' ', '-') 
  		FROM [pgl].[dbo].[IPL_UNIT_AREA] g
  		JOIN [pgl].[dbo].[IPL_UNIT_AREA_CLASS] h ON g.IUA_AREA_CLASS_ID = h.IUAC_ID 
  		JOIN [pgl].[dbo].[IPL_UNIT_AREA_FEE_DETAIL] j ON h.IUAC_ID = j.IUAFD_AREA_CLASS_ID
  		JOIN [pgl].[dbo].[IPL_UNIT_AREA_FEE] z ON j.IUAFD_FEE_ID = z.IUAF_ID
  		WHERE g.IUA_ID = a.IUA_ID 
  		ORDER BY j.IUAFD_CREATED DESC
  	) AS TIPE_IPL,
  	(
  		SELECT TOP 1
  			(j.IUAFD_SK + '-' + REPLACE(h.IUAC_CODE, ' ', '-'))
  		FROM [pgl].[dbo].[IPL_UNIT_AREA] g
  		JOIN [pgl].[dbo].[IPL_UNIT_AREA_CLASS] h ON g.IUA_AREA_CLASS_ID = h.IUAC_ID 
  		JOIN [pgl].[dbo].[IPL_UNIT_AREA_FEE_DETAIL] j ON h.IUAC_ID = j.IUAFD_AREA_CLASS_ID
  		JOIN [pgl].[dbo].[IPL_UNIT_AREA_FEE] z ON j.IUAFD_FEE_ID = z.IUAF_ID
  		WHERE g.IUA_ID = a.IUA_ID 
  		ORDER BY j.IUAFD_CREATED DESC
  	) AS KEY_IPL
  FROM 
  	[pgl].[dbo].[IPL_UNIT_AREA] a, 
  	(
  		SELECT 
  			DISTINCT(IUAO_AREA_ID), 
  			(
  				SELECT TOP 1 IUAO_CUSTOMER_ID 
  				FROM [pgl].[dbo].[IPL_UNIT_AREA_OCCUPIED] 
  				WHERE IUAO_AREA_ID = x.IUAO_AREA_ID
  				ORDER BY IUAO_ID DESC
  			) AS IUAO_CUSTOMER_ID, 
  			(
  				SELECT TOP 1 IUAO_PPJB_DATE 
  				FROM [pgl].[dbo].[IPL_UNIT_AREA_OCCUPIED] 
  				WHERE IUAO_AREA_ID = x.IUAO_AREA_ID 
  				ORDER BY IUAO_ID DESC
  			) AS IUAO_PPJB_DATE 
  		FROM [pgl].[dbo].[IPL_UNIT_AREA_OCCUPIED] x
  	) o,
  	(SELECT * FROM [pgl].[dbo].[IPL_UNIT_CUSTOMER]) c
  WHERE
  	a.IUA_ID = o.IUAO_AREA_ID AND 
  	o.IUAO_CUSTOMER_ID = c.IUC_ID AND 
  	a.IUA_CODE IN (
  		SELECT DISTINCT(KODE_BLOK)
  		FROM KWT_PEMBAYARAN_AI b 
  		WHERE 
  			b.KODE_BLOK NOT IN (SELECT KODE_BLOK FROM KWT_PELANGGAN)
  		GROUP BY b.KODE_BLOK
  	)
  GO 
  
  --- =================
  TRUNCATE TABLE KWT_CLUSTER 
  GO 
  INSERT INTO KWT_CLUSTER 
  ( 
  	KODE_CLUSTER, 
  	KODE_SEKTOR, 
  	NAMA_CLUSTER 
  ) 
  SELECT 
  	KODE_CLUSTER, 
  	KODE_SEKTOR, 
  	NAMA_CLUSTER 
  FROM [pgl].[dbo].[KWT_CLUSTER] 
  GO 
  
  -- KWT_CLUSTER ASP 
  INSERT INTO KWT_CLUSTER 
  ( 
  	KODE_CLUSTER, 
  	KODE_SEKTOR, 
  	NAMA_CLUSTER 
  ) 
  SELECT 
  	IUCLS_ID AS KODE_CLUSTER, 
  	NULL AS KODE_SEKTOR, 
  	IUCLS_NAME AS NAMA_CLUSTER 
  FROM [pgl].[dbo].[IPL_UNIT_CLUSTER] 
  GO 
  
  -- ==================
  UPDATE KWT_PEMBAYARAN_AI SET KODE_CLUSTER = '005' WHERE KODE_CLUSTER = '65' AND STATUS_BLOK ! = 3
  UPDATE KWT_PELANGGAN SET KODE_CLUSTER = '005' WHERE KODE_CLUSTER = '65' AND STATUS_BLOK ! = 3
  GO 
  
  -- MASSIVE UPDATE (LIKE A BOSS) KODE_SEKTOR, KWT_CLUSTER
  DECLARE 
  @kc3 VARCHAR(50), 
  @kc2 VARCHAR(50),
  @ks VARCHAR(50)
  	
  DECLARE cur_kc CURSOR FOR 
  SELECT KODE_CLUSTER AS KC3, 
  	( 
  		SELECT KODE_CLUSTER 
  		FROM KWT_CLUSTER 
  		WHERE 
  			LEN(KODE_CLUSTER) < 3 AND 
  			NAMA_CLUSTER = c.NAMA_CLUSTER 
  	) AS KC2, 
  	KODE_SEKTOR AS KS 
  FROM KWT_CLUSTER c 
  WHERE LEN(KODE_CLUSTER) > 2 
  OPEN cur_kc 
  
  FETCH NEXT FROM cur_kc INTO @kc3, @kc2, @ks 
  
  WHILE @@FETCH_STATUS = 0 
  BEGIN 
  
  	IF (@kc2 IS NOT NULL) BEGIN 
  		UPDATE KWT_PELANGGAN 
  		SET 
  			KODE_CLUSTER = @kc3, 
  			KODE_SEKTOR = @ks 
  		WHERE KODE_CLUSTER = @kc2 
  		
  		UPDATE KWT_PEMBAYARAN_AI 
  		SET 
  			KODE_CLUSTER = @kc3, 
  			KODE_SEKTOR = @ks 
  		WHERE KODE_CLUSTER = @kc2 
  		 
  		DELETE FROM KWT_CLUSTER WHERE KODE_CLUSTER = @kc2 
  	END 
  	 
  	FETCH NEXT FROM cur_kc INTO @kc3, @kc2, @ks 
  END 
  
  CLOSE cur_kc 
  DEALLOCATE cur_kc 
  GO 
  
  
  -- ================== UPDATE PELANGGAN BARU ==================
  DECLARE 
  @cou_np NUMERIC(25) = (SELECT TOP 1 COU_NP+1 FROM KWT_PARAMETER), 
  @kp VARCHAR(100),
  @onp VARCHAR(100)
  	
  DECLARE cur_np CURSOR FOR 
  SELECT 
  	CAST(p.NO_PELANGGAN AS VARCHAR(100)) AS ONP, 
  	(ISNULL(s.KODE_PEL,'00') + CAST(RIGHT(YEAR(GETDATE()),2) AS VARCHAR) + '0') AS KP
  FROM 
  	KWT_PELANGGAN p
  	LEFT JOIN KWT_SEKTOR s ON p.KODE_SEKTOR = s.KODE_SEKTOR
  WHERE STATUS_BLOK = 9
  ORDER BY CAST(p.NO_PELANGGAN AS INT)
  	
  OPEN cur_np 
  FETCH NEXT FROM cur_np INTO @onp, @kp 
  
  WHILE @@FETCH_STATUS = 0 
  BEGIN 
  	UPDATE KWT_PELANGGAN 
  	SET NO_PELANGGAN = @kp + RIGHT('0000000' + CAST(@cou_np AS VARCHAR(100)), 7)
  	WHERE NO_PELANGGAN = @onp
  	
  	SET @cou_np = @cou_np + 1;
  	
  	FETCH NEXT FROM cur_np INTO @onp, @kp
  END 
  
  UPDATE KWT_PARAMETER SET COU_NP = @cou_np
  
  CLOSE cur_np 
  DEALLOCATE cur_np 
  GO 
  
  
  
  
  -- ================== UPDATE PEMBAYARAN (NO_PELANGGAN, LUAS_KAVLING)
  UPDATE b SET 
  	b.NO_PELANGGAN = p.NO_PELANGGAN
  FROM 
  	KWT_PEMBAYARAN_AI b 
  	JOIN KWT_PELANGGAN p ON b.KODE_BLOK = p.KODE_BLOK 
  WHERE b.STATUS_BLOK ! = 3
  GO 
  
  -- ================== UPDATE PEMBAYARAN (ID_PEMBAYARAN)
  UPDATE KWT_PEMBAYARAN_AI 
  SET ID_PEMBAYARAN = (CAST(TRX AS VARCHAR(1)) + '#' + PERIODE_TAG + '#' + NO_PELANGGAN)
  WHERE STATUS_BLOK ! = 3
  GO
  
  -- ================== UPDATE PELANGGAN (KODE_SEKTOR KODE_CLUSTER)
  UPDATE p SET 
  	p.KODE_CLUSTER = c.KODE_CLUSTER,
  	p.KODE_SEKTOR = s.KODE_SEKTOR
  FROM 
  	KWT_PELANGGAN p 
  	JOIN KWT_CLUSTER c ON p.KODE_CLUSTER = c.KODE_CLUSTER
  	JOIN KWT_SEKTOR s ON c.KODE_SEKTOR = s.KODE_SEKTOR
  WHERE p.STATUS_BLOK ! = 3
  GO 
  
  -- ================== UPDATE PEMBAYARAN (KODE_SEKTOR KODE_CLUSTER)
  UPDATE b SET 
  	b.KODE_CLUSTER = p.KODE_CLUSTER,
  	b.KODE_SEKTOR = p.KODE_SEKTOR,
  	b.LUAS_KAVLING = p.LUAS_KAVLING
  FROM 
  	KWT_PEMBAYARAN_AI b 
  	JOIN KWT_PELANGGAN p ON b.KODE_BLOK = p.KODE_BLOK
  WHERE b.STATUS_BLOK ! = 3
  GO 
  
  -- ================== UPDATE KEY PELANGGAN
  UPDATE p SET 
  	p.STATUS_BLOK = ISNULL((
  		SELECT TOP 1 STATUS_BLOK 
  		FROM KWT_PEMBAYARAN_AI 
  		WHERE KODE_BLOK = p.KODE_BLOK
  		ORDER BY STATUS_BLOK DESC, CAST(PERIODE_TAG AS INT) DESC 
  	), p.STATUS_BLOK)
  FROM 
  	KWT_PELANGGAN p 
  WHERE p.STATUS_BLOK ! = 3
  GO 
  
  UPDATE KWT_PELANGGAN 
  SET KEY_AIR = REPLACE(KEY_AIR, ' ', '-'), 
  	KEY_IPL = REPLACE(KEY_IPL, ' ', '-'), 
  	TIPE_AIR = REPLACE(TIPE_AIR, ' ', '-'), 
  	TIPE_IPL = REPLACE(TIPE_IPL, ' ', '-') 
  GO 
  
  UPDATE KWT_PELANGGAN SET AKTIF_AIR = 1 WHERE KEY_AIR IS NOT NULL AND KEY_AIR NOT LIKE '%X0%'
  UPDATE KWT_PELANGGAN SET AKTIF_IPL = 1 WHERE KEY_IPL IS NOT NULL AND KEY_IPL NOT LIKE '%X0%' 
  UPDATE KWT_PELANGGAN SET AKTIF_AIR = 0 WHERE KEY_AIR IS NULL OR KEY_AIR LIKE '%X0%'
  UPDATE KWT_PELANGGAN SET AKTIF_IPL = 0 WHERE KEY_IPL IS NULL OR KEY_IPL LIKE '%X0%'
  GO 
  
  -- UPDATE GOLONGAN & TIPE_DENDA AIR
  UPDATE KWT_PELANGGAN 
  SET GOLONGAN = 1, TIPE_DENDA = 1
  WHERE
  	KEY_AIR LIKE '%B%'
  	OR KEY_IPL LIKE '%KB%' 
  	OR KEY_IPL LIKE '%BB%' 
  	OR KEY_IPL LIKE '%MB%' 	
  GO 
  
  UPDATE KWT_PELANGGAN 
  SET GOLONGAN = 1, TIPE_DENDA = 1
  WHERE KEY_AIR LIKE '%B%' 
  GO 
  
  UPDATE KWT_PEMBAYARAN_AI 
  SET GOLONGAN = 1, TIPE_DENDA = 1
  WHERE
  	KEY_AIR LIKE '%B%'
  	OR KEY_IPL LIKE '%KB%' 
  	OR KEY_IPL LIKE '%BB%' 
  	OR KEY_IPL LIKE '%MB%' 	
  GO 
  
  UPDATE KWT_PEMBAYARAN_AI 
  SET GOLONGAN = 1, TIPE_DENDA = 1
  WHERE KEY_AIR LIKE '%B%' 
  GO 
  
  -- ================== UPDATE KEY
  UPDATE KWT_PEMBAYARAN_AI SET 
  	KEY_AIR = REPLACE(KEY_AIR, ' ', '-'),
  	KEY_IPL = REPLACE(KEY_IPL, ' ', '-')
  GO
  
  -- ================== UPDATE USERS
  -- ================== UPDATE USER
  UPDATE b SET 
  	b.USER_BAYAR = ISNULL(CAST(k.ID_USER AS VARCHAR), b.USER_BAYAR), 
  	b.USER_CETAK_KWT = ISNULL(CAST(p.ID_USER AS VARCHAR), b.USER_CETAK_KWT), 
  	
  	b.USER_DISKON_AIR = ISNULL(CAST(ua.ID_USER AS VARCHAR), b.USER_DISKON_AIR), 
  	b.USER_DISKON_IPL = ISNULL(CAST(ui.ID_USER AS VARCHAR), b.USER_DISKON_IPL), 
  	b.USER_BATAL = ISNULL(CAST(ub.ID_USER AS VARCHAR), b.USER_BATAL), 
  	
  	b.USER_MODIFIED = ISNULL(CAST(m.ID_USER AS VARCHAR), b.USER_MODIFIED), 
  	b.USER_CREATED = ISNULL(CAST(c.ID_USER AS VARCHAR), b.USER_CREATED) 
  FROM 
  	KWT_PEMBAYARAN_AI b 
  	LEFT JOIN KWT_USER k ON b.USER_BAYAR = k.LOGIN_USER 
  	LEFT JOIN KWT_USER p ON b.USER_CETAK_KWT = p.LOGIN_USER 
  
  	LEFT JOIN KWT_USER ua ON b.USER_DISKON_AIR = ua.LOGIN_USER 
  	LEFT JOIN KWT_USER ui ON b.USER_DISKON_IPL = ui.LOGIN_USER 
  	LEFT JOIN KWT_USER ub ON b.USER_BATAL = ub.LOGIN_USER 
  
  	LEFT JOIN KWT_USER m ON b.USER_MODIFIED = m.LOGIN_USER 
  	LEFT JOIN KWT_USER c ON b.USER_CREATED = c.LOGIN_USER 
  GO 
  
  
  UPDATE KWT_PEMBAYARAN_AI SET USER_BAYAR = '1' WHERE USER_BAYAR = '-' AND STATUS_BAYAR = 1
  
  -- SET KE VIRTUALACCOUNT (2)
  UPDATE KWT_PEMBAYARAN_AI SET USER_BAYAR = '2' WHERE USER_BAYAR IS NULL AND STATUS_BAYAR = 1
  UPDATE KWT_PEMBAYARAN_AI SET USER_BAYAR = '2' WHERE USER_BAYAR = 'VIRTUAL ACCOUNT'
  UPDATE KWT_PEMBAYARAN_AI SET USER_MODIFIED = '2' WHERE USER_MODIFIED LIKE '%VIRTUAL ACCOUNT%'
  GO
  
  -- ================== UPDATE TAGIHAN CANCEL ==================
  UPDATE KWT_PEMBAYARAN_AI 
  SET STATUS_BAYAR = 1
  WHERE (JUMLAH_AIR + ABONEMEN + JUMLAH_IPL + ADM + DENDA - DISKON_AIR - DISKON_IPL) < 1 
  GO
  
  -- ============ UPDATE ++ ==================
  UPDATE KWT_PELANGGAN SET NO_HP = NULL WHERE NO_HP = '-'
  UPDATE KWT_PELANGGAN SET SM_NO_HP = NULL WHERE SM_NO_HP = '-'
  
  UPDATE KWT_PELANGGAN SET NO_TELEPON = NULL WHERE NO_TELEPON = '- / -'
  UPDATE KWT_PELANGGAN SET NO_TELEPON = REPLACE(NO_TELEPON, '- / ', '')
  UPDATE KWT_PELANGGAN SET NO_TELEPON = REPLACE(NO_TELEPON, ' / -', '')
  UPDATE KWT_PELANGGAN SET SM_NO_TELEPON = NULL WHERE SM_NO_TELEPON = '- / -'
  UPDATE KWT_PELANGGAN SET SM_NO_TELEPON = REPLACE(SM_NO_TELEPON, '- / ', '')
  UPDATE KWT_PELANGGAN SET SM_NO_TELEPON = REPLACE(SM_NO_TELEPON, ' / -', '')
  
  UPDATE KWT_PELANGGAN 
  SET NO_REKENING = dbo.TRIM(NO_REKENING), 
  	KODE_BANK = dbo.TRIM(KODE_BANK),
  	NO_HP = dbo.TRIM(NO_HP),
  	SM_NO_HP = dbo.TRIM(SM_NO_HP),
  	NO_TELEPON = dbo.TRIM(NO_TELEPON), 
  	SM_NO_TELEPON = dbo.TRIM(SM_NO_TELEPON)
  
  UPDATE KWT_PELANGGAN SET NO_REKENING = NULL WHERE NO_REKENING = ''
  UPDATE KWT_PELANGGAN SET KODE_BANK = NULL WHERE KODE_BANK = ''
  UPDATE KWT_PELANGGAN SET NO_HP = NULL WHERE NO_HP = ''
  UPDATE KWT_PELANGGAN SET SM_NO_HP = NULL WHERE SM_NO_HP = ''
  UPDATE KWT_PELANGGAN SET NO_TELEPON = NULL WHERE NO_TELEPON = ''
  UPDATE KWT_PELANGGAN SET SM_NO_TELEPON = NULL WHERE SM_NO_TELEPON = '' 
  GO 
  
  -- ================== ERROR CHECKING ================== 
  SELECT 
  	(SELECT COUNT(USER_BAYAR) FROM KWT_PEMBAYARAN_AI WHERE USER_BAYAR IS NOT NULL AND USER_BAYAR NOT IN (SELECT CAST(ID_USER AS VARCHAR) FROM KWT_USER)) AS USER_BAYAR, 
  	(SELECT COUNT(USER_CETAK_KWT) FROM KWT_PEMBAYARAN_AI WHERE USER_CETAK_KWT IS NOT NULL AND USER_CETAK_KWT NOT IN (SELECT CAST(ID_USER AS VARCHAR) FROM KWT_USER)) AS USER_CETAK_KWT, 
  	
  	(SELECT COUNT(USER_DISKON_AIR) FROM KWT_PEMBAYARAN_AI WHERE USER_DISKON_AIR IS NOT NULL AND USER_DISKON_AIR NOT IN (SELECT CAST(ID_USER AS VARCHAR) FROM KWT_USER)) AS USER_DISKON_AIR, 
  	(SELECT COUNT(USER_DISKON_IPL) FROM KWT_PEMBAYARAN_AI WHERE USER_DISKON_IPL IS NOT NULL AND USER_DISKON_IPL NOT IN (SELECT CAST(ID_USER AS VARCHAR) FROM KWT_USER)) AS USER_DISKON_IPL, 
  	(SELECT COUNT(USER_BATAL) FROM KWT_PEMBAYARAN_AI WHERE USER_BATAL IS NOT NULL AND USER_BATAL NOT IN (SELECT CAST(ID_USER AS VARCHAR) FROM KWT_USER)) AS USER_BATAL, 
  	
  	(SELECT COUNT(USER_MODIFIED) FROM KWT_PEMBAYARAN_AI WHERE USER_MODIFIED IS NOT NULL AND USER_MODIFIED NOT IN (SELECT CAST(ID_USER AS VARCHAR) FROM KWT_USER)) AS USER_MODIFIED, 
  	(SELECT COUNT(USER_CREATED) FROM KWT_PEMBAYARAN_AI WHERE USER_CREATED IS NOT NULL AND USER_CREATED NOT IN (SELECT CAST(ID_USER AS VARCHAR) FROM KWT_USER)) AS USER_CREATED 
  GO 
  
  
  SELECT DISTINCT KEY_IPL AS KEY_IPL_KWT_PELANGGAN_NOT_IN_MASTER 
  FROM KWT_PELANGGAN 
  WHERE KEY_IPL NOT IN (SELECT KEY_IPL FROM KWT_TARIF_IPL) 
  GO 
  SELECT DISTINCT KEY_AIR AS KEY_AIR_KWT_PELANGGAN_NOT_IN_MASTER 
  FROM KWT_PELANGGAN 
  WHERE KEY_AIR NOT IN (SELECT KEY_AIR FROM KWT_TARIF_AIR) 
  GO 
  
  
  SELECT DISTINCT KEY_IPL AS KEY_IPL_KWT_PEMBAYARAN_AI_NOT_IN_MASTER 
  FROM KWT_PEMBAYARAN_AI 
  WHERE KEY_IPL NOT IN (SELECT KEY_IPL FROM KWT_TARIF_IPL) 
  GO 
  SELECT DISTINCT KEY_AIR AS KEY_AIR_KWT_PEMBAYARAN_AI_NOT_IN_MASTER 
  FROM KWT_PEMBAYARAN_AI 
  WHERE KEY_AIR NOT IN (SELECT KEY_AIR FROM KWT_TARIF_AIR) 
  GO 
  
  
  SELECT KODE_BLOK, KODE_SEKTOR, '' AS KODE_SEKTOR_KWT_PELANGGAN_NOT_IN_KWT_SEKTOR 
  FROM KWT_PELANGGAN 
  WHERE KODE_SEKTOR NOT IN (SELECT KODE_SEKTOR FROM KWT_SEKTOR) 
  ORDER BY KODE_BLOK, KODE_SEKTOR 
  GO 
  SELECT KODE_BLOK, KODE_CLUSTER, '' AS KODE_CLUSTER_KWT_PELANGGAN_NOT_IN_KWT_CLUSTER 
  FROM KWT_PELANGGAN 
  WHERE KODE_CLUSTER NOT IN (SELECT KODE_CLUSTER FROM KWT_CLUSTER) 
  ORDER BY KODE_BLOK, KODE_CLUSTER
  GO 
  
  
  SELECT KODE_BLOK, KODE_SEKTOR, '' AS KODE_SEKTOR_KWT_PEMBAYARAN_AI_NOT_IN_KWT_SEKTOR 
  FROM KWT_PEMBAYARAN_AI 
  WHERE KODE_SEKTOR NOT IN (SELECT KODE_SEKTOR FROM KWT_SEKTOR) 
  ORDER BY KODE_BLOK, KODE_SEKTOR
  GO 
  SELECT KODE_BLOK, KODE_CLUSTER, '' AS KODE_CLUSTER_KWT_PEMBAYARAN_AI_NOT_IN_KWT_CLUSTER 
  FROM KWT_PEMBAYARAN_AI 
  WHERE KODE_CLUSTER NOT IN (SELECT KODE_CLUSTER FROM KWT_CLUSTER) 
  ORDER BY KODE_BLOK, KODE_CLUSTER
  GO 
  
  
  SELECT DISTINCT NO_PELANGGAN AS NO_PELANGGAN_KWT_PEMBAYARAN_AI_NOT_IN_MASTER 
  FROM KWT_PEMBAYARAN_AI 
  WHERE NO_PELANGGAN NOT IN (SELECT NO_PELANGGAN FROM KWT_PELANGGAN)
  GO 
  SELECT DISTINCT KODE_BLOK AS KODE_BLOK_KWT_PEMBAYARAN_AI_NOT_IN_MASTER 
  FROM KWT_PEMBAYARAN_AI 
  WHERE KODE_BLOK NOT IN (SELECT KODE_BLOK FROM KWT_PELANGGAN)
  GO 
  
  
  SELECT COUNT(KODE_BLOK) AS KODE_BLOK, '' AS KWT_PELANGGAN_STATUS_BLOK_BELUM_FIX
  FROM KWT_PELANGGAN WHERE STATUS_BLOK = 9
  GO 
  
  
  
  