-- customer2organisationhistory
INSERT INTO customer2organisationhistory(Customer2OrganisationOid,
										 CustomerOid,
										 OrganisationOid,
										 Tid,
										 Type,
										 Notice,
										 Info1,
										 Info2,
										 Info3,
										 Info4,
										 Info5,
										 InsTs,
										 InsUser,
										 Version,
										 UdpUser,
										 Customer2OrganisationInsTs,
										 Customer2OrganisationInsUser,
										 Customer2OrganisationVersion,
										 Customer2OrganisationUdpUser,
										 IsActive,
									 	 ChangeType)
								  SELECT Oid,
										 CustomerOid,
										 OrganisationOid,
										 76,
										 Type,
										 Notice,
										 Info1,
										 Info2,
										 Info3,
										 Info4,
										 Info5,
										 InsTs,
										 InsUser,
										 Version,
										 UdpUser,
										 InsTs,
										 InsUser,
										 Version,
										 UdpUser,
										 1,
										 0
								  FROM customer2organisation;


-- customer2personhistory
INSERT INTO customer2personhistory(CustomerOid,
								   customer2personOid,
								   PersonOid,
								   Tid,
								   Type,
								   Notice,
								   InsTs,
								   InsUser,
								   Version,
								   UdpUser,
								   ChangeType,
								   customer2personInsTs,
								   customer2personInsUser,
								   customer2personVersion,
								   customer2personUdpUser,
								   IsActive)
							SELECT CustomerOid,
								   Oid,
								   PersonOid,
								   75,
								   Type,
								   Notice,
								   InsTs,
								   InsUser,
								   1,
								   UdpUser,
								   0,
								   InsTs,
								   InsUser,
								   Version,
								   UdpUser,
								   1
							FROM customer2person;


-- employee2customerhistory
INSERT INTO employee2customerhistory(CustomerOid,
									 EmployeeOid,
									 Employee2CustomerOid,
									 Tid,
									 Notice,
									 InsTs,
									 InsUser,
									 Version,
									 UdpUser,
									 ChangeType,
									 Employee2CustomerInsTs,
									 Employee2CustomerInsUser,
									 Employee2CustomerVersion,
									 Employee2CustomerUdpUser,
									 IsActive)
							  SELECT CustomerOid,
							         EmployeeOid,
									 Oid,
									 77,
									 Notice,
									 InsTs,
									 InsUser,
									 1,
									 UdpUser,
									 0,
									 InsTs,
									 InsUser,
									 Version,
									 UdpUser,
									 1
							  FROM employee2customer;


-- customerhistory:
INSERT INTO customerhistory(Tid,
							Version,
							InsUser,
							UdpUser,
							InsTs,
							ChangeType,
							CustomerOid,
							PersonOid,
							ReferenceNumber,
							EquityContribution,
							Diagnosis,
							ICD10Diagnosis,
							Childs,
							Notice,
							CustomerInsTs,
							CustomerInsUser,
							CustomerVersion,
							CustomerUdpUser,
							IsActive,
							SystemEntryID,
							TerminationValueListEntryOid,
							TerminationDate,
							DebitorNumber,
							IsAdvisedOrAttended,
							Medication,
							CostCenter,
							Environment)
					 SELECT 74,
							1,
							InsUser,
							UdpUser,
							InsTs,
							0,
							Oid,
							PersonOid,
							ReferenceNumber,
							EquityContribution,
							Diagnosis,
							ICD10Diagnosis,
							Childs,
							Notice,
							InsTs,
							InsUser,
							Version,
							UdpUser,
							1,
							NULL,
							TerminationValueListEntryOid,
							TerminationDate,
							DebitorNumber,
							IsAdvisedOrAttended,
							Medication,
							CostCenter,
							Environment
					 FROM customer;


-- servicerecordhistroy:
INSERT INTO servicerecordhistory(Tid,
                                 Version,
                                 TimeStamp,
								 InsUser,
								 UdpUser,
								 InsTs,
								 ChangeType,
								 ServiceRecordOid,
								 CustomerOid,
								 EmployeeOid,
								 SupportConceptOid,
								 CostBearer2SupportConceptOid,
								 ServiceDescriptionOid,
								 StartDate,
								 EndDate,
								 IP,
								 RoundedDuration,
								 Notice,
								 ServiceRecordInsTs,
								 ServiceRecordInsUser,
								 ServiceRecordVersion,
								 ServiceRecordUdpUser,
								 GroupPersonCount,
								 GroupEmployeeCount,
								 GroupRoundedDuration,
								 GroupOid,
								 ServiceRecordType,
								 IsActive,
								 SystemEntryID) 
					      SELECT 73,
								 1,
								 InsTs,
								 InsUser,
								 UdpUser,
								 InsTs,
								 0,
								 Oid,
								 CustomerOid,
								 EmployeeOid,
								 SupportConceptOid,
								 CostBearer2SupportConceptOid,
								 ServiceDescriptionOid,
								 StartDate,
                                 EndDate,
								 IP,
								 RoundedDuration,
								 Notice,
								 InsTs,
								 InsUser,
								 Version,
								 UdpUser,
								 GroupPersonCount,
								 GroupEmployeeCount,
								 GroupRoundedDuration,
								 GroupOid,
								 ServiceRecordType,
								 1,
								 NULL
						  FROM servicerecord;