@echo off call "C:\GlobalCube\Tasks\scripts\config2.bat" rem ==VPP5R== del C:\GlobalCube\System\OPTIMA\SQL\logs\VPP5R*.* /Q /F >nul 2>nul if not "%1"=="" goto :increment :full call sql_query.bat "TRUNCATE TABLE [OPTIMA].[import].[VPP5R]" call bcp_queryout.bat "VPP5R_1" "SELECT T1.[VEHICLE_TYPE], T1.[STATE_CODE_PARAM], T1.[TRANSACT_DATE], T1.[HANDLER], T1.[VEHICLE_TYPE_TEXT], T1.[VEHICLE_TYPE_NEW], T1.[COST_ACC_USED], T1.[BONUS_ACC_USED], T1.[USE_DELIVERY_STOP_DAYS], T1.[DELIVERY_STOP_AFTER_DAYS], T1.[timestamp], T1.[UNIQUE_IDENT], '1' as [Client_DB] FROM [deop01].[dbo].[vPP5R] T1 WHERE 1 = 1 ORDER BY T1.[timestamp] " call bcp_in.bat "VPP5R_1" "[import].[VPP5R]" "OPTIMA" call bcp_queryout.bat "VPP5R_2" "SELECT T1.[VEHICLE_TYPE], T1.[STATE_CODE_PARAM], T1.[TRANSACT_DATE], T1.[HANDLER], T1.[VEHICLE_TYPE_TEXT], T1.[VEHICLE_TYPE_NEW], T1.[COST_ACC_USED], T1.[BONUS_ACC_USED], T1.[USE_DELIVERY_STOP_DAYS], T1.[DELIVERY_STOP_AFTER_DAYS], T1.[timestamp], T1.[UNIQUE_IDENT], '2' as [Client_DB] FROM [deop02].[dbo].[vPP5R] T1 WHERE 1 = 1 ORDER BY T1.[timestamp] " call bcp_in.bat "VPP5R_2" "[import].[VPP5R]" "OPTIMA" goto :cleanup :increment call sql_query.bat "TRUNCATE TABLE [OPTIMAX].[temp].[VPP5R]" call sql_timestamp.bat "VPP5R_1" "[OPTIMA].[import].[VPP5R]" "1" call bcp_queryout.bat "VPP5R_1" "SELECT T1.[VEHICLE_TYPE], T1.[STATE_CODE_PARAM], T1.[TRANSACT_DATE], T1.[HANDLER], T1.[VEHICLE_TYPE_TEXT], T1.[VEHICLE_TYPE_NEW], T1.[COST_ACC_USED], T1.[BONUS_ACC_USED], T1.[USE_DELIVERY_STOP_DAYS], T1.[DELIVERY_STOP_AFTER_DAYS], T1.[timestamp], T1.[UNIQUE_IDENT], '1' as [Client_DB] FROM [deop01].[dbo].[vPP5R] T1 WHERE T1.[timestamp] > convert(binary(8), '%TS%', 1) AND 1 = 1 ORDER BY T1.[timestamp] " call bcp_in.bat "VPP5R_1" "[temp].[VPP5R]" "OPTIMAX" call sql_timestamp.bat "VPP5R_2" "[OPTIMA].[import].[VPP5R]" "2" call bcp_queryout.bat "VPP5R_2" "SELECT T1.[VEHICLE_TYPE], T1.[STATE_CODE_PARAM], T1.[TRANSACT_DATE], T1.[HANDLER], T1.[VEHICLE_TYPE_TEXT], T1.[VEHICLE_TYPE_NEW], T1.[COST_ACC_USED], T1.[BONUS_ACC_USED], T1.[USE_DELIVERY_STOP_DAYS], T1.[DELIVERY_STOP_AFTER_DAYS], T1.[timestamp], T1.[UNIQUE_IDENT], '2' as [Client_DB] FROM [deop02].[dbo].[vPP5R] T1 WHERE T1.[timestamp] > convert(binary(8), '%TS%', 1) AND 1 = 1 ORDER BY T1.[timestamp] " call bcp_in.bat "VPP5R_2" "[temp].[VPP5R]" "OPTIMAX" call sql_query.bat "DELETE T1 FROM [OPTIMA].[import].[VPP5R] T1 INNER JOIN [OPTIMAX].[temp].[VPP5R] T2 ON T1.[CLIENT_DB] = T2.[CLIENT_DB] AND T1.[VEHICLE_TYPE] = T2.[VEHICLE_TYPE]" call sql_query.bat "INSERT INTO [OPTIMA].[import].[VPP5R] with (TABLOCK) SELECT * FROM [OPTIMAX].[temp].[VPP5R] T1" :cleanup call delete.bat "C:\GlobalCube\System\OPTIMA\SQL\temp\VPP5R_1.csv" call delete.bat "C:\GlobalCube\System\OPTIMA\SQL\temp\VPP5R_2.csv"