DECLARE @table_name VARCHAR(max)
DECLARE list_col CURSOR FAST_FORWARD FOR 
SELECT 
	[name]
FROM 
	SYSOBJECTS
WHERE
	crdate >= '2023-06-12'	-- mulai kapan dicreate
	AND xtype = 'U'	-- jenisnya table
OPEN list_col
FETCH NEXT FROM list_col INTO @table_name
WHILE @@FETCH_STATUS = 0 
BEGIN

	IF NOT EXISTS(
				SELECT
					*
				FROM
					INFORMATION_SCHEMA.COLUMNS AS c
					INNER JOIN
					SYSOBJECTS AS o ON c.TABLE_NAME = o.name
					INNER JOIN
					sys.partitions AS p ON o.id = p.object_id
				WHERE
					c.TABLE_NAME = @table_name
					AND (
						c.COLUMN_NAME = 'ETLExecutionName'
						OR c.COLUMN_NAME = 'ETLExecutionDate'
						)
					AND o.xtype = 'U'
					AND p.index_id < 2 -- 0:Heap, 1:Clustered 
				)
		BEGIN
			PRINT 'ALTER TABLE [SIPM].['+@table_name+'] ADD [ETLExecutionName] [varchar](255) NULL, [ETLExecutionDate] [datetime] NULL'
			--EXEC('ALTER TABLE [SIPM].['+@table_name+'] ADD [ETLExecutionName] [varchar](255) NULL, [ETLExecutionDate] [datetime] NULL')
		END

	FETCH NEXT FROM list_col INTO @table_name 
END
CLOSE list_col 
DEALLOCATE list_col

--select * from INFORMATION_SCHEMA.TABLES
--select * from SYSOBJECTS
--SELECT * FROM SYS.TABLES
--SELECT * FROM INFORMATION_SCHEMA.TABLES
--WHERE TABLE_TYPE = 'BASE TABLE'