SELECT [id_email_notification]
      ,[id_transaction_type]
      ,[id_unit_pelayanan_create]
      ,[email_to]
      ,[email_cc]
      ,[status]
      ,[create_by]
      ,[create_date]
      ,[change_by]
      ,[change_date]
  FROM [WebBranches].[dbo].[email_notification]
WHERE id_transaction_type IN (5) ORDER BY id_transaction_type, id_unit_pelayanan_create
SELECT
	*
FROM
	dbo.transaction_type
WHERE
  id_transaction_type IN (SELECT DISTINCT	id_transaction_type FROM email_notification)
  AND status='I'
ORDER BY
  description

SELECT
	*
FROM
	dbo.transaction_type
WHERE
  status = 'I'
  AND id_transaction_type NOT IN (SELECT id_transaction_type FROM dbo.transaction_type WHERE id_transaction_type IN (SELECT DISTINCT	id_transaction_type FROM email_notification) AND status='I')
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
--DECLARE @id_transaction_type TINYINT
--DECLARE list_cursor CURSOR FAST_FORWARD FOR  
--SELECT
--	id_transaction_type
--FROM
--	dbo.transaction_type
--WHERE
--  status = 'I'
--  AND id_transaction_type NOT IN (SELECT id_transaction_type FROM dbo.transaction_type WHERE id_transaction_type IN (SELECT DISTINCT	id_transaction_type FROM email_notification) AND status='I')

--OPEN list_cursor  
--FETCH NEXT FROM list_cursor INTO @id_transaction_type  
--WHILE @@FETCH_STATUS = 0  
--BEGIN 
--  INSERT INTO [WebBranches].[dbo].[email_notification]
--             ([id_transaction_type]
--             ,[id_unit_pelayanan_create]
--             ,[email_to]
--             ,[email_cc]
--             ,[status]
--             ,[create_by]
--             ,[create_date]
--             ,[change_by]
--             ,[change_date])
--  SELECT
--  	  @id_transaction_type,
--  	  id_unit_pelayanan_create,
--  	  email_to,
--  	  email_cc,
--  	  status,
--  	  create_by,
--  	  GETDATE(),
--  	  'SUP',
--  	  GETDATE()
--  FROM
--  	dbo.email_notification
--  WHERE
--    id_transaction_type = 5
--  FETCH NEXT FROM list_cursor INTO @id_transaction_type  
--END  

--CLOSE list_cursor  
--DEALLOCATE list_cursor 