INSERT INTO SGGLDB_WH.dbo.Sys_CodeRecords
select *
from SUBHSSEDB_WH.dbo.Sys_CodeRecords as s
where s.ProjectId in (select ProjectId from SGGLDB_WH.dbo.Base_Project) 
AND s.DataId  IN (select MonthReportId from SGGLDB_WH.dbo.Manager_MonthReportC) 
go

INSERT INTO SGGLDB_WH.dbo.Sys_CodeRecords
select *
from SUBHSSEDB_WH.dbo.Sys_CodeRecords as s
where s.ProjectId in (select ProjectId from SGGLDB_WH.dbo.Base_Project) 
AND s.DataId  IN (select RectifyNoticesId from SGGLDB_WH.dbo.Check_RectifyNotices) 
AND s.DataId  not in  (select DataId from SGGLDB_WH.dbo.Sys_CodeRecords) 
go


INSERT INTO SGGLDB_WH.dbo.Sys_CodeRecords
select *
from SUBHSSEDB_WH.dbo.Sys_CodeRecords as s
where s.ProjectId in (select ProjectId from SGGLDB_WH.dbo.Base_Project) 
AND s.DataId  IN (select CheckColligationId from SGGLDB_WH.dbo.Check_CheckColligation) 
AND s.DataId  not in  (select DataId from SGGLDB_WH.dbo.Sys_CodeRecords) 
go


INSERT INTO SGGLDB_WH.dbo.Sys_CodeRecords
select *
from SUBHSSEDB_WH.dbo.Sys_CodeRecords as s
where s.ProjectId in (select ProjectId from SGGLDB_WH.dbo.Base_Project) 
AND s.DataId  IN (select CheckDayId from SGGLDB_WH.dbo.Check_CheckDay) 
AND s.DataId  not in  (select DataId from SGGLDB_WH.dbo.Sys_CodeRecords) 
go

INSERT INTO SGGLDB_WH.dbo.Sys_CodeRecords
select *
from SUBHSSEDB_WH.dbo.Sys_CodeRecords as s
where s.ProjectId in (select ProjectId from SGGLDB_WH.dbo.Base_Project) 
AND s.DataId  IN (select CheckHolidayId from SGGLDB_WH.dbo.Check_CheckHoliday) 
AND s.DataId  not in  (select DataId from SGGLDB_WH.dbo.Sys_CodeRecords) 
go


INSERT INTO SGGLDB_WH.dbo.Sys_CodeRecords
select *
from SUBHSSEDB_WH.dbo.Sys_CodeRecords as s
where s.ProjectId in (select ProjectId from SGGLDB_WH.dbo.Base_Project) 
AND s.DataId  IN (select CheckWorkId from SGGLDB_WH.dbo.Check_CheckWork) 
AND s.DataId  not in  (select DataId from SGGLDB_WH.dbo.Sys_CodeRecords) 
go

INSERT INTO SGGLDB_WH.dbo.Sys_CodeRecords
select *
from SUBHSSEDB_WH.dbo.Sys_CodeRecords as s
where s.ProjectId in (select ProjectId from SGGLDB_WH.dbo.Base_Project) 
AND s.DataId  IN (select ManagerWeekId from SGGLDB_WH.dbo.Manager_ManagerWeek) 
AND s.DataId  not in  (select DataId from SGGLDB_WH.dbo.Sys_CodeRecords) 
go

INSERT INTO SGGLDB_WH.dbo.Sys_CodeRecords
select *
from SUBHSSEDB_WH.dbo.Sys_CodeRecords as s
where s.ProjectId in (select ProjectId from SGGLDB_WH.dbo.Base_Project) 
AND s.DataId  IN (select ManagerWeekId from SGGLDB_WH.dbo.Manager_ManagerWeek) 
AND s.DataId  not in  (select DataId from SGGLDB_WH.dbo.Sys_CodeRecords) 
go


INSERT INTO SGGLDB_WH.dbo.AttachFile(AttachFileId,ToKeyId,AttachSource,AttachUrl,MenuId,AttachPath)
select AttachFileId,ToKeyId,AttachSource,AttachUrl,MenuId,AttachPath
from SUBHSSEDB_WH.dbo.AttachFile as s
where  s.ToKeyId  not in  (select ToKeyId from SGGLDB_WH.dbo.AttachFile) 
go
