@echo off call "C:\GlobalCube\Tasks\scripts\config2.bat" rem ==PERSON_INFO== del C:\GlobalCube\System\OPTIMA\SQL\logs\PERSON_INFO*.* /Q /F >nul 2>nul if not "%1"=="" goto :increment :full call sql_query.bat "TRUNCATE TABLE [OPTIMA].[import].[PERSON_INFO]" call bcp_queryout.bat "PERSON_INFO_1" "SELECT T1.[PERSON_GROUP], T1.[PERSON_NUMBER], T1.[NAME], T1.[PERS_DEPARTMENT], T1.[PERS_STATE_CODE], T1.[TRANSACT_DATE], T1.[HANDLER], T1.[PERS_PERSON_CODE], T1.[PERS_STREET_ADDR], T1.[PERS_MAIL_ADDR], T1.[PERS_ZIPCODE], T1.[PERS_PHONE], T1.[PERS_SEX], T1.[PERS_TASK], T1.[PERS_BIRTH_PLACE], T1.[PERS_BANK], T1.[PERS_ACCT_NR], T1.[PERS_JOB_START], T1.[PERS_JOB_END], T1.[PERS_MECHNO_GROUP], T1.[PERS_UNION_START], T1.[PERS_MM_HOURS], T1.[PERS_ACT_CODE], T1.[PERS_PERSONAL_NO], T1.[PERS_OVERWORK], T1.[PERS_EFF_AW_DIV], T1.[OVERWORK_TIME], T1.[ADDR_3], T1.[COUNTY], T1.[DEF_DAY_ACTIVITY], T1.[DEF_JOB_ORDER_ACTIVITY], T1.[DEF_JOB_ACTIVITY], T1.[PERSON_NUMBER_NUM], T1.[WORKSHOP_TEAM], T1.[CONV_FLAG], T1.[timestamp], T1.[UNIQUE_IDENT], '1' as [Client_DB] FROM [deop01].[dbo].[PERSON_INFO] T1 WHERE 1 = 1 ORDER BY T1.[timestamp] " call bcp_in.bat "PERSON_INFO_1" "[import].[PERSON_INFO]" "OPTIMA" call bcp_queryout.bat "PERSON_INFO_2" "SELECT T1.[PERSON_GROUP], T1.[PERSON_NUMBER], T1.[NAME], T1.[PERS_DEPARTMENT], T1.[PERS_STATE_CODE], T1.[TRANSACT_DATE], T1.[HANDLER], T1.[PERS_PERSON_CODE], T1.[PERS_STREET_ADDR], T1.[PERS_MAIL_ADDR], T1.[PERS_ZIPCODE], T1.[PERS_PHONE], T1.[PERS_SEX], T1.[PERS_TASK], T1.[PERS_BIRTH_PLACE], T1.[PERS_BANK], T1.[PERS_ACCT_NR], T1.[PERS_JOB_START], T1.[PERS_JOB_END], T1.[PERS_MECHNO_GROUP], T1.[PERS_UNION_START], T1.[PERS_MM_HOURS], T1.[PERS_ACT_CODE], T1.[PERS_PERSONAL_NO], T1.[PERS_OVERWORK], T1.[PERS_EFF_AW_DIV], T1.[OVERWORK_TIME], T1.[ADDR_3], T1.[COUNTY], T1.[DEF_DAY_ACTIVITY], T1.[DEF_JOB_ORDER_ACTIVITY], T1.[DEF_JOB_ACTIVITY], T1.[PERSON_NUMBER_NUM], T1.[WORKSHOP_TEAM], T1.[CONV_FLAG], T1.[timestamp], T1.[UNIQUE_IDENT], '2' as [Client_DB] FROM [deop02].[dbo].[PERSON_INFO] T1 WHERE 1 = 1 ORDER BY T1.[timestamp] " call bcp_in.bat "PERSON_INFO_2" "[import].[PERSON_INFO]" "OPTIMA" goto :cleanup :increment call sql_query.bat "TRUNCATE TABLE [OPTIMAX].[temp].[PERSON_INFO]" call sql_timestamp.bat "PERSON_INFO_1" "[OPTIMA].[import].[PERSON_INFO]" "1" call bcp_queryout.bat "PERSON_INFO_1" "SELECT T1.[PERSON_GROUP], T1.[PERSON_NUMBER], T1.[NAME], T1.[PERS_DEPARTMENT], T1.[PERS_STATE_CODE], T1.[TRANSACT_DATE], T1.[HANDLER], T1.[PERS_PERSON_CODE], T1.[PERS_STREET_ADDR], T1.[PERS_MAIL_ADDR], T1.[PERS_ZIPCODE], T1.[PERS_PHONE], T1.[PERS_SEX], T1.[PERS_TASK], T1.[PERS_BIRTH_PLACE], T1.[PERS_BANK], T1.[PERS_ACCT_NR], T1.[PERS_JOB_START], T1.[PERS_JOB_END], T1.[PERS_MECHNO_GROUP], T1.[PERS_UNION_START], T1.[PERS_MM_HOURS], T1.[PERS_ACT_CODE], T1.[PERS_PERSONAL_NO], T1.[PERS_OVERWORK], T1.[PERS_EFF_AW_DIV], T1.[OVERWORK_TIME], T1.[ADDR_3], T1.[COUNTY], T1.[DEF_DAY_ACTIVITY], T1.[DEF_JOB_ORDER_ACTIVITY], T1.[DEF_JOB_ACTIVITY], T1.[PERSON_NUMBER_NUM], T1.[WORKSHOP_TEAM], T1.[CONV_FLAG], T1.[timestamp], T1.[UNIQUE_IDENT], '1' as [Client_DB] FROM [deop01].[dbo].[PERSON_INFO] T1 WHERE T1.[timestamp] > convert(binary(8), '%TS%', 1) AND 1 = 1 ORDER BY T1.[timestamp] " call bcp_in.bat "PERSON_INFO_1" "[temp].[PERSON_INFO]" "OPTIMAX" call sql_timestamp.bat "PERSON_INFO_2" "[OPTIMA].[import].[PERSON_INFO]" "2" call bcp_queryout.bat "PERSON_INFO_2" "SELECT T1.[PERSON_GROUP], T1.[PERSON_NUMBER], T1.[NAME], T1.[PERS_DEPARTMENT], T1.[PERS_STATE_CODE], T1.[TRANSACT_DATE], T1.[HANDLER], T1.[PERS_PERSON_CODE], T1.[PERS_STREET_ADDR], T1.[PERS_MAIL_ADDR], T1.[PERS_ZIPCODE], T1.[PERS_PHONE], T1.[PERS_SEX], T1.[PERS_TASK], T1.[PERS_BIRTH_PLACE], T1.[PERS_BANK], T1.[PERS_ACCT_NR], T1.[PERS_JOB_START], T1.[PERS_JOB_END], T1.[PERS_MECHNO_GROUP], T1.[PERS_UNION_START], T1.[PERS_MM_HOURS], T1.[PERS_ACT_CODE], T1.[PERS_PERSONAL_NO], T1.[PERS_OVERWORK], T1.[PERS_EFF_AW_DIV], T1.[OVERWORK_TIME], T1.[ADDR_3], T1.[COUNTY], T1.[DEF_DAY_ACTIVITY], T1.[DEF_JOB_ORDER_ACTIVITY], T1.[DEF_JOB_ACTIVITY], T1.[PERSON_NUMBER_NUM], T1.[WORKSHOP_TEAM], T1.[CONV_FLAG], T1.[timestamp], T1.[UNIQUE_IDENT], '2' as [Client_DB] FROM [deop02].[dbo].[PERSON_INFO] T1 WHERE T1.[timestamp] > convert(binary(8), '%TS%', 1) AND 1 = 1 ORDER BY T1.[timestamp] " call bcp_in.bat "PERSON_INFO_2" "[temp].[PERSON_INFO]" "OPTIMAX" call sql_query.bat "DELETE T1 FROM [OPTIMA].[import].[PERSON_INFO] T1 INNER JOIN [OPTIMAX].[temp].[PERSON_INFO] T2 ON T1.[CLIENT_DB] = T2.[CLIENT_DB] AND T1.[PERSON_NUMBER] = T2.[PERSON_NUMBER]" call sql_query.bat "INSERT INTO [OPTIMA].[import].[PERSON_INFO] with (TABLOCK) SELECT * FROM [OPTIMAX].[temp].[PERSON_INFO] T1" :cleanup call delete.bat "C:\GlobalCube\System\OPTIMA\SQL\temp\PERSON_INFO_1.csv" call delete.bat "C:\GlobalCube\System\OPTIMA\SQL\temp\PERSON_INFO_2.csv"