DECLARE @toinsertmd125 TABLE ( [StartDate] VARCHAR(8) ,[EndDate] VARCHAR (8) ,[EmployeeID] VARCHAR (20) ,[DayType] VARCHAR(50) ,[PublicHoliday] VARCHAR(50) ,[Notes] VARCHAR(500) ,[CreateBy] VARCHAR(100) ,[CreateDate] VARCHAR(100) ,[ChangeBy] VARCHAR(100) ,[ChangeDate] VARCHAR(100) ) insert into @toinsertmd125 select cal.DateSpecified, cal.DateSpecified,pa25.EmployeeID, cal.DayType, cal.PublicHoliday ,'','system',format(getdate(),'yyyyMMddHHmmssffff'),'system',format(getdate(),'yyyyMMddHHmmssffff') from phrpa0025 pa25 left join PHRTMWSCAL cal on pa25.WorkScheduleType = cal.WorkScheduleType and cal.year ='2024' where pa25.WorkScheduleType = 'OVT' and pa25.StartDate = '20240101' --SELECT * FROM @toinsertmd125 --INSERT INTO dbo.PHRPA0125 --SELECT DISTINCT [StartDate],[EndDate],[EmployeeID],[DayType],[PublicHoliday],[Notes],[CreateBy],[CreateDate],[ChangeBy],[ChangeDate] FROM @toinsertmd125