USE [SISIMPU]
GO

create table Master.TEMP_MAPPING_ORG
(
    ID                 int identity
        constraint TEMP_MAPPING_ORG_pk
            primary key nonclustered,
    OrganizaionId      int,
    OrganizationIdBaru int
)
go

create unique index TEMP_MAPPING_ORG_ID_uindex
    on Master.TEMP_MAPPING_ORG (ID)
go


INSERT INTO Master.TEMP_MAPPING_ORG (OrganizaionId, OrganizationIdBaru) VALUES (100, 30);
INSERT INTO Master.TEMP_MAPPING_ORG (OrganizaionId, OrganizationIdBaru) VALUES (101, 30);
INSERT INTO Master.TEMP_MAPPING_ORG (OrganizaionId, OrganizationIdBaru) VALUES (102, 30);
INSERT INTO Master.TEMP_MAPPING_ORG (OrganizaionId, OrganizationIdBaru) VALUES (124, 89);
INSERT INTO Master.TEMP_MAPPING_ORG (OrganizaionId, OrganizationIdBaru) VALUES (125, 89);
INSERT INTO Master.TEMP_MAPPING_ORG (OrganizaionId, OrganizationIdBaru) VALUES (127, 90);
INSERT INTO Master.TEMP_MAPPING_ORG (OrganizaionId, OrganizationIdBaru) VALUES (128, 90);
INSERT INTO Master.TEMP_MAPPING_ORG (OrganizaionId, OrganizationIdBaru) VALUES (129, 92);
INSERT INTO Master.TEMP_MAPPING_ORG (OrganizaionId, OrganizationIdBaru) VALUES (131, 92);
INSERT INTO Master.TEMP_MAPPING_ORG (OrganizaionId, OrganizationIdBaru) VALUES (132, 93);
INSERT INTO Master.TEMP_MAPPING_ORG (OrganizaionId, OrganizationIdBaru) VALUES (134, 93);
INSERT INTO Master.TEMP_MAPPING_ORG (OrganizaionId, OrganizationIdBaru) VALUES (136, 95);
INSERT INTO Master.TEMP_MAPPING_ORG (OrganizaionId, OrganizationIdBaru) VALUES (140, 98);
INSERT INTO Master.TEMP_MAPPING_ORG (OrganizaionId, OrganizationIdBaru) VALUES (151, 28);
INSERT INTO Master.TEMP_MAPPING_ORG (OrganizaionId, OrganizationIdBaru) VALUES (161, 188);
INSERT INTO Master.TEMP_MAPPING_ORG (OrganizaionId, OrganizationIdBaru) VALUES (165, 7);
INSERT INTO Master.TEMP_MAPPING_ORG (OrganizaionId, OrganizationIdBaru) VALUES (190, 11);


-- EMPLOYEES
UPDATE a SET a.EmployeeOrganizationId = b.OrganizationIdBaru
FROM Master.Employees a
INNER JOIN Master.TEMP_MAPPING_ORG b ON a.EmployeeOrganizationId = b.OrganizaionId

-- PROLEG
UPDATE a SET a.ProlegOrganizationId = b.OrganizationIdBaru
FROM [Transaction].Proleg a
INNER JOIN Master.TEMP_MAPPING_ORG b ON a.ProlegOrganizationId = b.OrganizaionId

-- REGULATIONS
UPDATE a SET a.RegulationOrganizationId = b.OrganizationIdBaru
FROM [Transaction].Regulations a
INNER JOIN Master.TEMP_MAPPING_ORG b ON a.RegulationOrganizationId = b.OrganizaionId

-- DOCUMENT
UPDATE a SET a.DocumentOrganizationId = b.OrganizationIdBaru
FROM [Transaction].Document a
INNER JOIN Master.TEMP_MAPPING_ORG b ON a.DocumentOrganizationId = b.OrganizaionId


DROP TABLE Master.TEMP_MAPPING_ORG