use staging_namecheck;
go

SET ANSI_NULLS ON
SET ANSI_PADDING ON;
SET QUOTED_IDENTIFIER ON
go

declare @s varchar(4000) = '';

IF OBJECT_ID('[dbo].[TXM_Batch_scoring_raw_N]', 'U') IS NULL
begin
	CREATE TABLE [dbo].[TXM_Batch_scoring_raw_N](
		UserBank_id varchar(50) NOT NULL,
		Customer_id varchar(50) NOT NULL,
		Customer_nr varchar(50) NULL,
		Branch_id varchar(50) NULL,
		CustomerType_cd varchar(10) NULL,
		CustomerType_Descr varchar(4000) NULL,
		Profile_code int NOT NULL,
		ProfileType_cd varchar(10) NULL,
		CustomerFirstName varchar(100) NULL,
		CustomerLastName varchar(100) NULL,
		CustomerFullName varchar(255) NULL,
		CustomerOpeningDate varchar(35) NULL, --datetime
		CustomerStatus_cd varchar(10) NULL,
		CustomerStatus_Descr varchar(4000) NULL,
		CustomerDateOfBirth varchar(35) NULL, --datetime
		CustomerPlaceOfBirth varchar(255) NULL,
		CustomerCountryOfBirth_cd varchar(10) NULL,
		CustomerDateOfDeath varchar(35) NULL, --datetime
		CustomerCitizenship1_cd varchar(10) NULL,
		CustomerCitizenship1_Name varchar(255) NULL,
		CustomerCitizenship1_ISO2 varchar(2) NULL,
		CustomerCitizenship2_cd varchar(10) NULL,
		CustomerGender_cd varchar(10) NULL,
		CustomerTitle_cd varchar(10) NULL,
		CustomerOccupation_cd varchar(10) NULL,
		CustomerTaxCountry_cd varchar(10) NULL,
		CustomerDomicile_flag int NULL,
		CustomerIncorporationNumber varchar(50) NULL,
		CustomerBuisinesCategory_cd varchar(10) NULL,
		CustomerLegalForm_cd varchar(10) NULL,
		CustomerLegalForm_Descr varchar(4000) NULL,
		CustomerParentCompanyResid_cd varchar(10) NULL,
		CustomerLegalCategory_cd varchar(10) NULL,
		CustomerFATCAStatus_cd varchar(10) NULL,
		CustomerBusinessRelation_cd varchar(10) NULL,
		CustomerIDCheckType_cd varchar(10) NULL,
		CustomerReferredEAM_cd varchar(10) NULL,
		CustomerComplexStructure_flag int NULL,
		CustomerGroupType_cd varchar(10) NULL,
		CustomerSizeCategory_cd varchar(10) NULL,
		CustomerLastChangeDate varchar(35) NULL, --datetime
		CustomerCivilStatus_cd varchar(10) NULL,
		CustomerRiskCategory_cd varchar(10) NULL,
		CustomerSegment_cd varchar(10) NULL,
		CustomerVip_flag int NULL,
		CustomerCategory_cd varchar(10) NULL,
		CustomerCategory_Descr varchar(4000) NULL,
		CustomerCapital numeric(15,2) NULL,
		Bank_flag int NULL,
		CustomerCommercialName varchar(255) NULL,
		CustomerEmail varchar(255) NULL,
		CustomerUrl varchar(255) NULL,
		CustomerTaxNumber varchar(100) NULL,
		CustomerTaxRegNumber varchar(100) NULL,
		CustomerMiddleName varchar(100) NULL,
		CustomerPrefixName varchar(100) NULL,
		CustomerMotherName varchar(255) NULL,
		CustomerAlias varchar(100) NULL,
		CustomerSSN varchar(25) NULL,
		CustomerPassportNumber varchar(255) NULL,
		CustomerPassportCountry_cd varchar(10) NULL,
		CustomerIDNumber varchar(255) NULL,
		CustomerCitizenship3_cd varchar(10) NULL,
		CustomerResidence_cd varchar(10) NULL,
		CustomerSourceOfWealth varchar(255) NULL,
		CustomerSalary_flag int NULL,
		CustomerEducationLevel_cd varchar(10) NULL,
		CustomerNetIncome numeric(15,2) NULL,
		CustomerAddIncome numeric(15,2) NULL,
		CustomerPhoneNumber varchar(100) NULL,
		SAR_flag int NULL,
		CustomerPepStatus_cd varchar(10) NULL,
		CustomerPepStatus_Descr varchar(4000) NULL,
		PEP_Description varchar(4000) NULL,
		PEP_Country_cd varchar(10) NULL,
		CustomerPEPCategory_cd varchar(10) NULL,
		CustomerSanctionStatus_flag int NULL,
		CustomerCrimeStatus_flag int NULL,
		CustomerInternStatus_flag int NULL,
		CustomerPepStatusOnboard_flag int NULL,
		CustomerComment varchar(4000) NULL,
		AddressStreet varchar(255) NULL,
		AddressTown varchar(255) NULL,
		AddressCity varchar(255) NULL,
		AddressRegion varchar(255) NULL,
		AddressPostCode varchar(20) NULL,
		AddressCountry_cd varchar(10) NULL,
		AddressCountry_Name varchar(255) NULL,
		AddressCountry_ISO2 varchar(2) NULL,
		AddressType_cd varchar(10) NULL,
		AddressOpenDate varchar(35) NULL, --datetime
		AddressExpiryDate varchar(35) NULL, --datetime
		AddressComment varchar(4000) NULL,
		HighRiskIndustry_flag numeric(1,0) NULL,
		IncompleteLegitimation_flag numeric(1,0) NULL,
		SHORT_KT_flag numeric(1,0) NULL,
		SHORT_KT_AMOUNT numeric(15,2) NULL,
		SHORT_KT_DURATION int NULL,
		SHORT_KT_Account_id varchar(50) NULL,
		KD_TOTAL_SALDO numeric(15,2) NULL,
		KT_CNT int NULL,
		KT_CNT_90d int NULL,
		KT_CNT_3d int NULL,
		CNT_INFLOW_Counterparty int NULL,
		Link_to_CPCollector_flag numeric(1,0) NULL,
		CPCollector_LIST varchar(4000) NULL,
		max_Partner_code int NULL,
		MAX_KT_DURATION int NULL,
		KD_AGE numeric(10,3) NULL,
		KD_DURATION numeric(9,2) NULL,
		KD_LAST_CHANGE int NULL,
		DEATH_flag numeric(1,0) NULL,
		Links_01 numeric(1,0) NULL,
		Contracts_01 numeric(1,0) NULL,
		PEP_RELATED_01 numeric(1,0) NULL,
		LinkType_list varchar(4000) NULL,
		CustomerB_id_list varchar(4000) NULL,
		EmploymentType_list varchar(4000) NULL,
		FundType_list varchar(4000) NULL,
		NewLink_flag numeric(1,0) NULL,
		NewSignatory_flag numeric(1,0) NULL,
		SUM_INFLOW_1d numeric(15,2) NULL,
		SUM_INFLOW_3d numeric(15,2) NULL,
		SUM_INFLOW_7d numeric(15,2) NULL,
		SUM_INFLOW_10d numeric(15,2) NULL,
		SUM_INFLOW_30d numeric(15,2) NULL,
		SUM_INFLOW_3m numeric(15,2) NULL,
		SUM_INFLOW_6m numeric(15,2) NULL,
		SUM_INFLOW_12m numeric(15,2) NULL,
		SUM_INFLOW_24m numeric(15,2) NULL,
		CNT_INFLOW_1d int NULL,
		CNT_INFLOW_3d int NULL,
		CNT_INFLOW_7d int NULL,
		CNT_INFLOW_10d int NULL,
		CNT_INFLOW_30d int NULL,
		CNT_INFLOW_3m int NULL,
		CNT_INFLOW_6m int NULL,
		CNT_INFLOW_12m int NULL,
		CNT_INFLOW_24m int NULL,
		SUM_OUTFLOW_1d numeric(15,2) NULL,
		SUM_OUTFLOW_3d numeric(15,2) NULL,
		SUM_OUTFLOW_7d numeric(15,2) NULL,
		SUM_OUTFLOW_10d numeric(15,2) NULL,
		SUM_OUTFLOW_30d numeric(15,2) NULL,
		SUM_OUTFLOW_3m numeric(15,2) NULL,
		SUM_OUTFLOW_6m numeric(15,2) NULL,
		SUM_OUTFLOW_12m numeric(15,2) NULL,
		SUM_OUTFLOW_24m numeric(15,2) NULL,
		CNT_OUTFLOW_1d int NULL,
		CNT_OUTFLOW_3d int NULL,
		CNT_OUTFLOW_7d int NULL,
		CNT_OUTFLOW_10d int NULL,
		CNT_OUTFLOW_30d int NULL,
		CNT_OUTFLOW_3m int NULL,
		CNT_OUTFLOW_6m int NULL,
		CNT_OUTFLOW_12m int NULL,
		CNT_OUTFLOW_24m int NULL,
		SUM_INFLOW_Dubious_3m numeric(15,2) NULL,
		CNT_INFLOW_Dubious_3m int NULL,
		SUM_INFLOW_CRYPTO_30d numeric(15,2) NULL,
		CNT_INFLOW_CRYPTO_30d int NULL,
		SUM_OUTFLOW_CRYPTO_30d numeric(15,2) NULL,
		CNT_OUTFLOW_CRYPTO_30d int NULL,
		SUM_OUTFLOW_CASH_30d numeric(15,2) NULL,
		CNT_OUTFLOW_CASH_30d int NULL,
		SUM_OUTFLOW_CASH_7d numeric(15,2) NULL,
		CNT_OUTFLOW_CASH_7d int NULL,
		SUM_OUTFLOW_CASH_3d numeric(15,2) NULL,
		CNT_OUTFLOW_CASH_3d int NULL,
		SUM_FOREIGN_INFLOW_3m numeric(15,2) NULL,
		SUM_FOREIGN_INFLOW_12m numeric(15,2) NULL,
		SUM_FOREIGN_OUTFLOW_3m numeric(15,2) NULL,
		SUM_FOREIGN_OUTFLOW_12m numeric(15,2) NULL,
		CNT_SMALL_INFLOWS_30d int NULL,
		CNT_SMALL_OUTFLOWS_30d int NULL,
		SUM_RETURNDEBIT_30d numeric(15,2) NULL,
		CNT_RETURNDEBIT_30d int NULL,
		SUM_ChequeDeposit_3d numeric(15,2) NULL,
		SUM_INFLOW_3RD_PARTY_14d numeric(15,2) NULL,
		CNT_INFLOW_3RD_PARTY_14d int NULL,
		SUM_INFLOW_MISMATCH_RECIPIENT_3d numeric(15,2) NULL,
		CNT_INFLOW_MISMATCH_RECIPIENT_3d int NULL,
		SUM_INFLOW_LOAN_30d numeric(15,2) NULL,
		CNT_INFLOW_LOAN_30d int NULL,
		SUM_GAMBLING_7d numeric(15,2) NULL,
		SUM_GAMBLING_30d numeric(15,2) NULL,
		SUM_GAMBLING_3m numeric(15,2) NULL,
		CNT_GAMBLING_7d int NULL,
		CNT_GAMBLING_30d int NULL,
		CNT_GAMBLING_3m int NULL,
		SUM_INOUT_1d numeric(15,2) NULL,
		SUM_INOUT_3d numeric(15,2) NULL,
		SUM_INOUT_7d numeric(15,2) NULL,
		SUM_INOUT_10d numeric(15,2) NULL,
		SUM_INOUT_30d numeric(15,2) NULL,
		SUM_INOUT_3m numeric(15,2) NULL,
		SUM_INOUT_6m numeric(15,2) NULL,
		SUM_INOUT_12m numeric(15,2) NULL,
		SUM_INOUT_24m numeric(15,2) NULL,
		CNT_INOUT_1d int NULL,
		CNT_INOUT_3d int NULL,
		CNT_INOUT_7d int NULL,
		CNT_INOUT_10d int NULL,
		CNT_INOUT_30d int NULL,
		CNT_INOUT_3m int NULL,
		CNT_INOUT_6m int NULL,
		CNT_INOUT_12m int NULL,
		CNT_INOUT_24m int NULL,
		SUM_FOREIGN_INOUT_3m numeric(15,2) NULL,
		SUM_FOREIGN_INOUT_12m numeric(15,2) NULL,
		AVG_INFLOW_1d numeric(15,2) NULL,
		AVG_INFLOW_3d numeric(15,2) NULL,
		AVG_INFLOW_7d numeric(15,2) NULL,
		AVG_INFLOW_10d numeric(15,2) NULL,
		AVG_INFLOW_30d numeric(15,2) NULL,
		AVG_INFLOW_3m numeric(15,2) NULL,
		AVG_INFLOW_6m numeric(15,2) NULL,
		AVG_INFLOW_12m numeric(15,2) NULL,
		AVG_INFLOW_24m numeric(15,2) NULL,
		AVG_OUTFLOW_1d numeric(15,2) NULL,
		AVG_OUTFLOW_3d numeric(15,2) NULL,
		AVG_OUTFLOW_7d numeric(15,2) NULL,
		AVG_OUTFLOW_10d numeric(15,2) NULL,
		AVG_OUTFLOW_30d numeric(15,2) NULL,
		AVG_OUTFLOW_3m numeric(15,2) NULL,
		AVG_OUTFLOW_6m numeric(15,2) NULL,
		AVG_OUTFLOW_12m numeric(15,2) NULL,
		AVG_OUTFLOW_24m numeric(15,2) NULL,
		MAX_KD_TOTAL_SALDO_3d numeric(15,2) NULL,
		MAX_KD_TOTAL_SALDO_30d numeric(15,2) NULL,
		SUM_KD_CURRENT_SALDO numeric(15,2) NULL,
		SUM_KD_SAVINGS_SALDO numeric(15,2) NULL,
		SUM_KD_LOAN_SALDO numeric(15,2) NULL,
		SUM_KD_CREDITCARD_SALDO numeric(15,2) NULL,
		SUM_KD_BUILDINGSAVINGS_SALDO numeric(15,2) NULL,
		SUM_KD_CAPITAL_SALDO numeric(15,2) NULL,
		SUM_KD_LIFEINSURANCE_SALDO numeric(15,2) NULL,
		SUM_KD_NONLIFEINSURANCE_SALDO numeric(15,2) NULL,
		CNT_KD_CURRENT_SALDO int NULL,
		CNT_KD_SAVINGS_SALDO int NULL,
		CNT_KD_LOAN_SALDO int NULL,
		CNT_KD_CREDITCARD_SALDO int NULL,
		CNT_KD_BUILDINGSAVINGS_SALDO int NULL,
		CNT_KD_CAPITAL_SALDO int NULL,
		CNT_KD_LIFEINSURANCE_SALDO int NULL,
		CNT_KD_NONLIFEINSURANCE_SALDO int NULL,
		AVG_KD_CURRENT_SALDO numeric(15,2) NULL,
		AVG_KD_SAVINGS_SALDO numeric(15,2) NULL,
		AVG_KD_LOAN_SALDO numeric(15,2) NULL,
		CNT_KD_Products int NULL,
		LastAccountOpenDate varchar(35) NULL,  --date
		AccountSourceOfFunds_list varchar(4000) NULL,
		ProductCode_cd_list varchar(4000) NULL,
		ProductCode_list varchar(4000) NULL,
		AccountType_cd_list varchar(4000) NULL,
		AccountType_list varchar(4000) NULL,
		AccountBlockType_cd_list varchar(4000) NULL,
		AccountBlockType_list varchar(4000) NULL,
		AgentContact_flag numeric(1,0) NULL,
		KD_BHVCLUSTER int NULL,
		KD_BHV_THRESHOLD numeric(15,2) NULL,
		KD_BHV_RISK numeric(10,8) NULL,
		MAX_DAY_SUM_AMOUNT_1Y numeric(15,2) NULL,
		MAX_CNT_MONTH_TRANS_1Y int NULL,
		CNT_MONTH_WITH_TRANS_1Y int NULL,
		MAX_TRANSACTION_1Y numeric(15,2) NULL,
		MAX_MONTH_SUM_AMOUNT_1Y numeric(15,2) NULL,
		MAX_MONTH_SUM_INFLOW_1Y numeric(15,2) NULL,
		MAX_MONTH_SUM_OUTFLOW_1Y numeric(15,2) NULL,
		AVG_KD_SALDO_1Y numeric(15,2) NULL,
		MAX_KD_SALDO_1Y numeric(15,2) NULL,
		T_DATE int NULL,
		KD_List_SanctionedPartner_01 int NULL,
		KD_List_KnownPEP_01 int NULL,
		KD_Alert_AdverseMedia_01 int NULL,
		KD_NegativeCharacter_flag int NULL,
		CNT_KD_prof_alerts_5d int NULL,
		CNT_KD_prof_alerts_10d int NULL,
		CNT_KD_prof_alerts_30d int NULL,
		CNT_KD_prof_alerts_60d int NULL,
		CNT_dif_rules_KD_prof_alerts_5d int NULL,
		CNT_dif_rules_KD_prof_alerts_10d int NULL,
		CNT_dif_rules_KD_prof_alerts_30d int NULL,
		CNT_dif_rules_KD_prof_alerts_60d int NULL,
		TW_DATL_1d int NULL,
		TW_DATL_3d int NULL,
		TW_DATL_7d int NULL,
		TW_DATL_10d int NULL,
		TW_DATL_30d int NULL,
		TW_DATL_3m int NULL,
		TW_DATL_6m int NULL,
		TW_DATL_12m int NULL,
		TW_DATL_24m int NULL,
		MSG varchar(7999) NULL,
		ScoreInterpretation varchar(100) NULL,
		RiskClass_N int NULL,
		RiskClass_MSG varchar(100) NULL,
		debug_dt_day varchar(255) NULL,
		TXM_CONFIG varchar(255) NULL,
		txm_chunk_id varchar(255) NULL,
		txm_chunk_id_internal varchar(255) NULL,
		txm_debug_NumRec varchar(255) NULL,
		txm_worker_comp_time float NULL,
		txm_worker_found_num float NULL,
		txm_worker_recno float NULL,
		txm_worker_tr_dt float NULL,
		score_5F03C6ED22324CE3AD84DEC601D19223 float NULL,
		sign_5F03C6ED22324CE3AD84DEC601D19223 int NULL,
		class_5F03C6ED22324CE3AD84DEC601D19223 float NULL,
		REC_ID bigint IDENTITY (1,1) NOT NULL
	) ON [PRIMARY];

	set @s = @s + 'TXM_Batch_scoring_raw_N has been created; ';
end;

--drop old indexes
if exists (select * from sys.indexes where [name]='TXM_Batch_scoring_raw_NC1' 
	and object_id = object_id('[dbo].[TXM_Batch_scoring_raw_N]'))
begin
	drop index TXM_Batch_scoring_raw_NC1 on [dbo].[TXM_Batch_scoring_raw_N];
	set @s = @s + 'TXM_Batch_scoring_raw_NC1-index has been dropped on TXM_Batch_scoring_raw_N; ';
end;

if exists (select * from sys.indexes where [name]='TXM_Batch_scoring_raw_NI2' 
	and object_id = object_id('[dbo].[TXM_Batch_scoring_raw_N]'))
begin
	drop index TXM_Batch_scoring_raw_NI2 on [dbo].[TXM_Batch_scoring_raw_N];	
	set @s = @s + 'TXM_Batch_scoring_raw_NI2-index has been dropped on TXM_Batch_scoring_raw_N; ';
end;

if exists (select * from sys.indexes where [name]='TXM_Batch_scoring_raw_NI3' 
	and object_id = object_id('[dbo].[TXM_Batch_scoring_raw_N]'))
begin
	drop index TXM_Batch_scoring_raw_NI3 on [dbo].[TXM_Batch_scoring_raw_N];	
	set @s = @s + 'TXM_Batch_scoring_raw_NI3-index has been dropped on TXM_Batch_scoring_raw_N; ';
end;

if exists (select * from sys.indexes where [name]='TXM_Batch_scoring_raw_NI4' 
	and object_id = object_id('[dbo].[TXM_Batch_scoring_raw_N]'))
begin
	drop index TXM_Batch_scoring_raw_NI4 on [dbo].[TXM_Batch_scoring_raw_N];	
	set @s = @s + 'TXM_Batch_scoring_raw_NI4-index has been dropped on TXM_Batch_scoring_raw_N; ';
end;

if exists (select * from sys.indexes where [name]='TXM_Batch_scoring_raw_NI5' 
	and object_id = object_id('[dbo].[TXM_Batch_scoring_raw_N]'))
begin
	drop index TXM_Batch_scoring_raw_NI5 on [dbo].[TXM_Batch_scoring_raw_N];	
	set @s = @s + 'TXM_Batch_scoring_raw_NI5-index has been dropped on TXM_Batch_scoring_raw_N; ';
end;

if exists (select * from sys.indexes where [name]='TXM_Batch_scoring_raw_NI6' 
	and object_id = object_id('[dbo].[TXM_Batch_scoring_raw_N]'))
begin
	drop index TXM_Batch_scoring_raw_NI6 on [dbo].[TXM_Batch_scoring_raw_N];	
	set @s = @s + 'TXM_Batch_scoring_raw_NI6-index has been dropped on TXM_Batch_scoring_raw_N; ';
end;

if exists (select * from sys.indexes where [name]='CI_txm_chunk_id_REC_ID' 
	and object_id = object_id('[dbo].[TXM_Batch_scoring_raw_N]'))
begin
	drop index CI_txm_chunk_id_REC_ID on [dbo].[TXM_Batch_scoring_raw_N];	
	set @s = @s + 'CI_txm_chunk_id_REC_ID-index has been dropped on TXM_Batch_scoring_raw_N; ';
end;

if exists (select * from sys.indexes where [name]='NC_UserBank_id_Customer_id_Include' 
	and object_id = object_id('[dbo].[TXM_Batch_scoring_raw_N]'))
begin
	drop index NC_UserBank_id_Customer_id_Include on [dbo].[TXM_Batch_scoring_raw_N];	
	set @s = @s + 'NC_UserBank_id_Customer_id_Include-index has been dropped on TXM_Batch_scoring_raw_N; ';
end;

if exists (select * from sys.indexes where [name]='TXM_Batch_scoring_raw_NI8' 
	and object_id = object_id('[dbo].[TXM_Batch_scoring_raw_N]'))
begin
	drop index TXM_Batch_scoring_raw_NI8 on [dbo].[TXM_Batch_scoring_raw_N];	
	set @s = @s + 'TXM_Batch_scoring_raw_NI8-index has been dropped on TXM_Batch_scoring_raw_N; ';
end;

if exists (select * from sys.columns where [name]='SUM_INFLOW_DIFSENDER_14d' 
	and object_id = object_id('[dbo].[TXM_Batch_scoring_raw_N]'))
begin
	alter table [dbo].[TXM_Batch_scoring_raw_N] drop column SUM_INFLOW_DIFSENDER_14d;
	set @s = @s + 'SUM_INFLOW_DIFSENDER_14d has been dropped in TXM_Batch_scoring_raw_N; ';
end;

if exists (select * from sys.columns where [name]='CNT_INFLOW_DIFSENDER_14d' 
	and object_id = object_id('[dbo].[TXM_Batch_scoring_raw_N]'))
begin
	alter table [dbo].[TXM_Batch_scoring_raw_N] drop column CNT_INFLOW_DIFSENDER_14d;
	set @s = @s + 'CNT_INFLOW_DIFSENDER_14d has been dropped in TXM_Batch_scoring_raw_N; ';
end;

if exists (select * from sys.columns where [name]='AgentContact_days' 
	and object_id = object_id('[dbo].[TXM_Batch_scoring_raw_N]'))
begin
	alter table [dbo].[TXM_Batch_scoring_raw_N] drop column AgentContact_days;
	set @s = @s + 'AgentContact_days has been dropped in TXM_Batch_scoring_raw_N; ';
end;


--alter/and new columns
if (select count(*) from sys.columns where [name]='Customer_id' 
	and object_id = object_id('[dbo].[TXM_Batch_scoring_raw_N]') and system_type_id<>167)>0
begin
	alter table [dbo].[TXM_Batch_scoring_raw_N] alter column [Customer_id] varchar(50) NOT NULL;
	set @s = @s + 'Customer_id has been altered in TXM_Batch_scoring_raw_N; ';
end;

if not exists (select * from sys.columns where [name]='CLASS_5F03C6ED22324CE3AD84DEC601D19223' 
	and object_id = object_id('[dbo].[TXM_Batch_scoring_raw_N]') and system_type_id=62)
begin
	alter table [dbo].[TXM_Batch_scoring_raw_N] alter column [class_5F03C6ED22324CE3AD84DEC601D19223] float NULL;
	set @s = @s + 'class_5F03C6ED22324CE3AD84DEC601D19223 has been altered in TXM_Batch_scoring_raw_N; ';
end;

if not exists (select * from sys.columns where [name]='SUM_OUTFLOW_CASH_30d' and object_id = object_id('[dbo].[TXM_Batch_scoring_raw_N]'))
	and exists (select * from sys.columns where [name]='SUM_OUTFLOW_ATM_30d' and object_id = object_id('[dbo].[TXM_Batch_scoring_raw_N]'))
begin
	EXEC sp_rename 'dbo.TXM_Batch_scoring_raw_N.SUM_OUTFLOW_ATM_30d', 'SUM_OUTFLOW_CASH_30d', 'COLUMN';
	set @s = @s + 'SUM_OUTFLOW_ATM_30d has been renamed into SUM_OUTFLOW_CASH_30d in TXM_Batch_scoring_raw_N; ';
end;

if not exists (select * from sys.columns where [name]='CNT_OUTFLOW_CASH_30d' and object_id = object_id('[dbo].[TXM_Batch_scoring_raw_N]'))
	and exists (select * from sys.columns where [name]='CNT_OUTFLOW_ATM_30d' and object_id = object_id('[dbo].[TXM_Batch_scoring_raw_N]'))
begin
	EXEC sp_rename 'dbo.TXM_Batch_scoring_raw_N.CNT_OUTFLOW_ATM_30d', 'CNT_OUTFLOW_CASH_30d', 'COLUMN';
	set @s = @s + 'CNT_OUTFLOW_ATM_30d has been renamed into CNT_OUTFLOW_CASH_30d in TXM_Batch_scoring_raw_N; ';
end;


if not exists (select * from sys.columns where [name]='CustomerCitizenship1_Name' 
	and object_id = object_id('[dbo].[TXM_Batch_scoring_raw_N]'))
begin
	alter table [dbo].[TXM_Batch_scoring_raw_N] add CustomerCitizenship1_Name varchar(255) NULL;
	set @s = @s + 'CustomerCitizenship1_Name has been added into TXM_Batch_scoring_raw_N; ';
end;

if not exists (select * from sys.columns where [name]='CustomerCitizenship1_ISO2' 
	and object_id = object_id('[dbo].[TXM_Batch_scoring_raw_N]'))
begin
	alter table [dbo].[TXM_Batch_scoring_raw_N] add CustomerCitizenship1_ISO2 varchar(2) NULL;
	set @s = @s + 'CustomerCitizenship1_ISO2 has been added into TXM_Batch_scoring_raw_N; ';
end;

if not exists (select * from sys.columns where [name]='CustomerLegalForm_Descr' 
	and object_id = object_id('[dbo].[TXM_Batch_scoring_raw_N]'))
begin
	alter table [dbo].[TXM_Batch_scoring_raw_N] add CustomerLegalForm_Descr varchar(4000) NULL;
	set @s = @s + 'CustomerLegalForm_Descr has been added into TXM_Batch_scoring_raw_N; ';
end;

if not exists (select * from sys.columns where [name]='CustomerCategory_Descr' 
	and object_id = object_id('[dbo].[TXM_Batch_scoring_raw_N]'))
begin
	alter table [dbo].[TXM_Batch_scoring_raw_N] add CustomerCategory_Descr varchar(4000) NULL;
	set @s = @s + 'CustomerCategory_Descr has been added into TXM_Batch_scoring_raw_N; ';
end;

if not exists (select * from sys.columns where [name]='AddressCountry_Name' 
	and object_id = object_id('[dbo].[TXM_Batch_scoring_raw_N]'))
begin
	alter table [dbo].[TXM_Batch_scoring_raw_N] add AddressCountry_Name varchar(255) NULL;
	set @s = @s + 'AddressCountry_Name has been added into TXM_Batch_scoring_raw_N; ';
end;

if not exists (select * from sys.columns where [name]='AddressCountry_ISO2' 
	and object_id = object_id('[dbo].[TXM_Batch_scoring_raw_N]'))
begin
	alter table [dbo].[TXM_Batch_scoring_raw_N] add AddressCountry_ISO2 varchar(2) NULL;
	set @s = @s + 'AddressCountry_ISO2 has been added into TXM_Batch_scoring_raw_N; ';
end;

if not exists (select * from sys.columns where [name]='max_Partner_code' 
	and object_id = object_id('[dbo].[TXM_Batch_scoring_raw_N]'))
begin
	alter table [dbo].[TXM_Batch_scoring_raw_N] add max_Partner_code int NULL;
	set @s = @s + 'max_Partner_code has been added into TXM_Batch_scoring_raw_N; ';
end;

if not exists (select * from sys.columns where [name]='CustomerType_Descr' 
	and object_id = object_id('[dbo].[TXM_Batch_scoring_raw_N]'))
begin
	alter table [dbo].[TXM_Batch_scoring_raw_N] add CustomerType_Descr varchar(4000) NULL;
	set @s = @s + 'CustomerType_Descr has been added into TXM_Batch_scoring_raw_N; ';
end;

if not exists (select * from sys.columns where [name]='CustomerStatus_Descr' 
	and object_id = object_id('[dbo].[TXM_Batch_scoring_raw_N]'))
begin
	alter table [dbo].[TXM_Batch_scoring_raw_N] add CustomerStatus_Descr varchar(4000) NULL;
	set @s = @s + 'CustomerStatus_Descr has been added into TXM_Batch_scoring_raw_N; ';
end;

if not exists (select * from sys.columns where [name]='CustomerPepStatus_Descr' 
	and object_id = object_id('[dbo].[TXM_Batch_scoring_raw_N]'))
begin
	alter table [dbo].[TXM_Batch_scoring_raw_N] add CustomerPepStatus_Descr varchar(4000) NULL;
	set @s = @s + 'CustomerPepStatus_Descr has been added into TXM_Batch_scoring_raw_N; ';
end;

if not exists (select * from sys.columns where [name]='REC_ID' 
	and object_id = object_id('[dbo].[TXM_Batch_scoring_raw_N]'))
begin
	EXEC sp_rename 'dbo.TXM_Batch_scoring_raw_N.FAF_POC_REC_ID', 'REC_ID', 'COLUMN';
	set @s = @s + 'FAF_POC_REC_ID has been renamed into REC_ID in TXM_Batch_scoring_raw_N; ';
end;

if not exists (select * from sys.columns where [name]='HighRiskIndustry_flag' 
	and object_id = object_id('[dbo].[TXM_Batch_scoring_raw_N]'))
begin
	alter table [dbo].[TXM_Batch_scoring_raw_N] add HighRiskIndustry_flag numeric(1,0) NULL;
	set @s = @s + 'HighRiskIndustry_flag has been added into TXM_Batch_scoring_raw_N; ';
end;

if not exists (select * from sys.columns where [name]='IncompleteLegitimation_flag' 
	and object_id = object_id('[dbo].[TXM_Batch_scoring_raw_N]'))
begin
	alter table [dbo].[TXM_Batch_scoring_raw_N] add IncompleteLegitimation_flag numeric(1,0) NULL;
	set @s = @s + 'IncompleteLegitimation_flag has been added into TXM_Batch_scoring_raw_N; ';
end;

if not exists (select * from sys.columns where [name]='SHORT_KT_flag' 
	and object_id = object_id('[dbo].[TXM_Batch_scoring_raw_N]'))
begin
	alter table [dbo].[TXM_Batch_scoring_raw_N] add SHORT_KT_flag numeric(1,0) NULL;
	set @s = @s + 'SHORT_KT_flag has been added into TXM_Batch_scoring_raw_N; ';
end;

if not exists (select * from sys.columns where [name]='SHORT_KT_AMOUNT' 
	and object_id = object_id('[dbo].[TXM_Batch_scoring_raw_N]'))
begin
	alter table [dbo].[TXM_Batch_scoring_raw_N] add SHORT_KT_AMOUNT numeric(15,2) NULL;
	set @s = @s + 'SHORT_KT_AMOUNT has been added into TXM_Batch_scoring_raw_N; ';
end;

if not exists (select * from sys.columns where [name]='SHORT_KT_DURATION' 
	and object_id = object_id('[dbo].[TXM_Batch_scoring_raw_N]'))
begin
	alter table [dbo].[TXM_Batch_scoring_raw_N] add SHORT_KT_DURATION int NULL;
	set @s = @s + 'SHORT_KT_DURATION has been added into TXM_Batch_scoring_raw_N; ';
end;

if not exists (select * from sys.columns where [name]='SHORT_KT_Account_id' 
	and object_id = object_id('[dbo].[TXM_Batch_scoring_raw_N]'))
begin
	alter table [dbo].[TXM_Batch_scoring_raw_N] add SHORT_KT_Account_id varchar(50) NULL;
	set @s = @s + 'SHORT_KT_Account_id has been added into TXM_Batch_scoring_raw_N; ';
end;

if (select count(*) from sys.columns where [name]='SHORT_KT_Account_id' 
	and object_id = object_id('[dbo].[TXM_Batch_scoring_raw_N]') and system_type_id<>167)>0
begin
	alter table [dbo].[TXM_Batch_scoring_raw_N] alter column SHORT_KT_Account_id varchar(50) NULL;
	set @s = @s + 'SHORT_KT_Account_id has been altered into TXM_Batch_scoring_raw_N; ';
end;

if not exists (select * from sys.columns where [name]='KT_CNT_90d' 
	and object_id = object_id('[dbo].[TXM_Batch_scoring_raw_N]'))
begin
	alter table [dbo].[TXM_Batch_scoring_raw_N] add KT_CNT_90d int NULL;
	set @s = @s + 'KT_CNT_90d has been added into TXM_Batch_scoring_raw_N; ';
end;

if not exists (select * from sys.columns where [name]='KT_CNT_3d' 
	and object_id = object_id('[dbo].[TXM_Batch_scoring_raw_N]'))
begin
	alter table [dbo].[TXM_Batch_scoring_raw_N] add KT_CNT_3d int NULL;
	set @s = @s + 'KT_CNT_3d has been added into TXM_Batch_scoring_raw_N; ';
end;

if not exists (select * from sys.columns where [name]='NewLink_flag' 
	and object_id = object_id('[dbo].[TXM_Batch_scoring_raw_N]'))
begin
	alter table [dbo].[TXM_Batch_scoring_raw_N] add NewLink_flag numeric(1,0) NULL;
	set @s = @s + 'NewLink_flag has been added into TXM_Batch_scoring_raw_N; ';
end;

if not exists (select * from sys.columns where [name]='NewSignatory_flag' 
	and object_id = object_id('[dbo].[TXM_Batch_scoring_raw_N]'))
begin
	alter table [dbo].[TXM_Batch_scoring_raw_N] add NewSignatory_flag numeric(1,0) NULL;
	set @s = @s + 'NewSignatory_flag has been added into TXM_Batch_scoring_raw_N; ';
end;

if not exists (select * from sys.columns where [name]='CNT_INFLOW_Counterparty' 
	and object_id = object_id('[dbo].[TXM_Batch_scoring_raw_N]'))
begin
	alter table [dbo].[TXM_Batch_scoring_raw_N] add CNT_INFLOW_Counterparty int NULL;
	set @s = @s + 'CNT_INFLOW_Counterparty has been added into TXM_Batch_scoring_raw_N; ';
end;

if not exists (select * from sys.columns where [name]='KD_NegativeCharacter_flag' 
	and object_id = object_id('[dbo].[TXM_Batch_scoring_raw_N]'))
begin
	alter table [dbo].[TXM_Batch_scoring_raw_N] add KD_NegativeCharacter_flag int NULL;
	set @s = @s + 'KD_NegativeCharacter_flag has been added into TXM_Batch_scoring_raw_N; ';
end;

if not exists (select * from sys.columns where [name]='TW_DATL_1d' 
	and object_id = object_id('[dbo].[TXM_Batch_scoring_raw_N]'))
begin
	alter table [dbo].[TXM_Batch_scoring_raw_N] add TW_DATL_1d int NULL;
	set @s = @s + 'TW_DATL_1d has been added into TXM_Batch_scoring_raw_N; ';
end;

if not exists (select * from sys.columns where [name]='TW_DATL_3d' 
	and object_id = object_id('[dbo].[TXM_Batch_scoring_raw_N]'))
begin
	alter table [dbo].[TXM_Batch_scoring_raw_N] add TW_DATL_3d int NULL;
	set @s = @s + 'TW_DATL_3d has been added into TXM_Batch_scoring_raw_N; ';
end;

if not exists (select * from sys.columns where [name]='TW_DATL_7d' 
	and object_id = object_id('[dbo].[TXM_Batch_scoring_raw_N]'))
begin
	alter table [dbo].[TXM_Batch_scoring_raw_N] add TW_DATL_7d int NULL;
	set @s = @s + 'TW_DATL_7d has been added into TXM_Batch_scoring_raw_N; ';
end;

if not exists (select * from sys.columns where [name]='TW_DATL_10d' 
	and object_id = object_id('[dbo].[TXM_Batch_scoring_raw_N]'))
begin
	alter table [dbo].[TXM_Batch_scoring_raw_N] add TW_DATL_10d int NULL;
	set @s = @s + 'TW_DATL_10d has been added into TXM_Batch_scoring_raw_N; ';
end;

if not exists (select * from sys.columns where [name]='TW_DATL_30d' 
	and object_id = object_id('[dbo].[TXM_Batch_scoring_raw_N]'))
begin
	alter table [dbo].[TXM_Batch_scoring_raw_N] add TW_DATL_30d int NULL;
	set @s = @s + 'TW_DATL_30d has been added into TXM_Batch_scoring_raw_N; ';
end;

if not exists (select * from sys.columns where [name]='TW_DATL_3m' 
	and object_id = object_id('[dbo].[TXM_Batch_scoring_raw_N]'))
begin
	alter table [dbo].[TXM_Batch_scoring_raw_N] add TW_DATL_3m int NULL;
	set @s = @s + 'TW_DATL_3m has been added into TXM_Batch_scoring_raw_N; ';
end;

if not exists (select * from sys.columns where [name]='TW_DATL_6m' 
	and object_id = object_id('[dbo].[TXM_Batch_scoring_raw_N]'))
begin
	alter table [dbo].[TXM_Batch_scoring_raw_N] add TW_DATL_6m int NULL;
	set @s = @s + 'TW_DATL_6m has been added into TXM_Batch_scoring_raw_N; ';
end;

if not exists (select * from sys.columns where [name]='TW_DATL_12m' 
	and object_id = object_id('[dbo].[TXM_Batch_scoring_raw_N]'))
begin
	alter table [dbo].[TXM_Batch_scoring_raw_N] add TW_DATL_12m int NULL;
	set @s = @s + 'TW_DATL_12m has been added into TXM_Batch_scoring_raw_N; ';
end;

if not exists (select * from sys.columns where [name]='TW_DATL_24m' 
	and object_id = object_id('[dbo].[TXM_Batch_scoring_raw_N]'))
begin
	alter table [dbo].[TXM_Batch_scoring_raw_N] add TW_DATL_24m int NULL;
	set @s = @s + 'TW_DATL_24m has been added into TXM_Batch_scoring_raw_N; ';
end;

if not exists (select * from sys.columns where [name]='Link_to_CPCollector_flag' 
	and object_id = object_id('[dbo].[TXM_Batch_scoring_raw_N]'))
begin
	alter table [dbo].[TXM_Batch_scoring_raw_N] add Link_to_CPCollector_flag numeric(1,0) NULL;
	set @s = @s + 'Link_to_CPCollector_flag has been added into TXM_Batch_scoring_raw_N; ';
end;

if not exists (select * from sys.columns where [name]='CPCollector_LIST' 
	and object_id = object_id('[dbo].[TXM_Batch_scoring_raw_N]'))
begin
	alter table [dbo].[TXM_Batch_scoring_raw_N] add CPCollector_LIST varchar(4000) NULL;
	set @s = @s + 'CPCollector_LIST has been added into TXM_Batch_scoring_raw_N; ';
end;

if not exists (select * from sys.columns where [name]='SUM_INFLOW_1d' 
	and object_id = object_id('[dbo].[TXM_Batch_scoring_raw_N]'))
begin
	alter table [dbo].[TXM_Batch_scoring_raw_N] add SUM_INFLOW_1d numeric(15,2) NULL;
	set @s = @s + 'SUM_INFLOW_1d has been added into TXM_Batch_scoring_raw_N; ';
end;

if not exists (select * from sys.columns where [name]='SUM_INFLOW_3d' 
	and object_id = object_id('[dbo].[TXM_Batch_scoring_raw_N]'))
begin
	alter table [dbo].[TXM_Batch_scoring_raw_N] add SUM_INFLOW_3d numeric(15,2) NULL;
	set @s = @s + 'SUM_INFLOW_3d has been added into TXM_Batch_scoring_raw_N; ';
end;

if not exists (select * from sys.columns where [name]='SUM_INFLOW_7d' 
	and object_id = object_id('[dbo].[TXM_Batch_scoring_raw_N]'))
begin
	alter table [dbo].[TXM_Batch_scoring_raw_N] add SUM_INFLOW_7d numeric(15,2) NULL;
	set @s = @s + 'SUM_INFLOW_7d has been added into TXM_Batch_scoring_raw_N; ';
end;

if not exists (select * from sys.columns where [name]='SUM_INFLOW_10d' 
	and object_id = object_id('[dbo].[TXM_Batch_scoring_raw_N]'))
begin
	alter table [dbo].[TXM_Batch_scoring_raw_N] add SUM_INFLOW_10d numeric(15,2) NULL;
	set @s = @s + 'SUM_INFLOW_10d has been added into TXM_Batch_scoring_raw_N; ';
end;

if not exists (select * from sys.columns where [name]='SUM_INFLOW_30d' 
	and object_id = object_id('[dbo].[TXM_Batch_scoring_raw_N]'))
begin
	alter table [dbo].[TXM_Batch_scoring_raw_N] add SUM_INFLOW_30d numeric(15,2) NULL;
	set @s = @s + 'SUM_INFLOW_30d has been added into TXM_Batch_scoring_raw_N; ';
end;

if not exists (select * from sys.columns where [name]='SUM_INFLOW_3m' 
	and object_id = object_id('[dbo].[TXM_Batch_scoring_raw_N]'))
begin
	alter table [dbo].[TXM_Batch_scoring_raw_N] add SUM_INFLOW_3m numeric(15,2) NULL;
	set @s = @s + 'SUM_INFLOW_3m has been added into TXM_Batch_scoring_raw_N; ';
end;

if not exists (select * from sys.columns where [name]='SUM_INFLOW_6m' 
	and object_id = object_id('[dbo].[TXM_Batch_scoring_raw_N]'))
begin
	alter table [dbo].[TXM_Batch_scoring_raw_N] add SUM_INFLOW_6m numeric(15,2) NULL;
	set @s = @s + 'SUM_INFLOW_6m has been added into TXM_Batch_scoring_raw_N; ';
end;

if not exists (select * from sys.columns where [name]='SUM_INFLOW_12m' 
	and object_id = object_id('[dbo].[TXM_Batch_scoring_raw_N]'))
begin
	alter table [dbo].[TXM_Batch_scoring_raw_N] add SUM_INFLOW_12m numeric(15,2) NULL;
	set @s = @s + 'SUM_INFLOW_12m has been added into TXM_Batch_scoring_raw_N; ';
end;

if not exists (select * from sys.columns where [name]='SUM_INFLOW_24m' 
	and object_id = object_id('[dbo].[TXM_Batch_scoring_raw_N]'))
begin
	alter table [dbo].[TXM_Batch_scoring_raw_N] add SUM_INFLOW_24m numeric(15,2) NULL;
	set @s = @s + 'SUM_INFLOW_24m has been added into TXM_Batch_scoring_raw_N; ';
end;

if not exists (select * from sys.columns where [name]='CNT_INFLOW_1d' 
	and object_id = object_id('[dbo].[TXM_Batch_scoring_raw_N]'))
begin
	alter table [dbo].[TXM_Batch_scoring_raw_N] add CNT_INFLOW_1d int NULL;
	set @s = @s + 'CNT_INFLOW_1d has been added into TXM_Batch_scoring_raw_N; ';
end;

if not exists (select * from sys.columns where [name]='CNT_INFLOW_3d' 
	and object_id = object_id('[dbo].[TXM_Batch_scoring_raw_N]'))
begin
	alter table [dbo].[TXM_Batch_scoring_raw_N] add CNT_INFLOW_3d int NULL;
	set @s = @s + 'CNT_INFLOW_3d has been added into TXM_Batch_scoring_raw_N; ';
end;

if not exists (select * from sys.columns where [name]='CNT_INFLOW_7d' 
	and object_id = object_id('[dbo].[TXM_Batch_scoring_raw_N]'))
begin
	alter table [dbo].[TXM_Batch_scoring_raw_N] add CNT_INFLOW_7d int NULL;
	set @s = @s + 'CNT_INFLOW_7d has been added into TXM_Batch_scoring_raw_N; ';
end;

if not exists (select * from sys.columns where [name]='CNT_INFLOW_10d' 
	and object_id = object_id('[dbo].[TXM_Batch_scoring_raw_N]'))
begin
	alter table [dbo].[TXM_Batch_scoring_raw_N] add CNT_INFLOW_10d int NULL;
	set @s = @s + 'CNT_INFLOW_10d has been added into TXM_Batch_scoring_raw_N; ';
end;

if not exists (select * from sys.columns where [name]='CNT_INFLOW_30d' 
	and object_id = object_id('[dbo].[TXM_Batch_scoring_raw_N]'))
begin
	alter table [dbo].[TXM_Batch_scoring_raw_N] add CNT_INFLOW_30d int NULL;
	set @s = @s + 'CNT_INFLOW_30d has been added into TXM_Batch_scoring_raw_N; ';
end;

if not exists (select * from sys.columns where [name]='CNT_INFLOW_3m' 
	and object_id = object_id('[dbo].[TXM_Batch_scoring_raw_N]'))
begin
	alter table [dbo].[TXM_Batch_scoring_raw_N] add CNT_INFLOW_3m int NULL;
	set @s = @s + 'CNT_INFLOW_3m has been added into TXM_Batch_scoring_raw_N; ';
end;

if not exists (select * from sys.columns where [name]='CNT_INFLOW_6m' 
	and object_id = object_id('[dbo].[TXM_Batch_scoring_raw_N]'))
begin
	alter table [dbo].[TXM_Batch_scoring_raw_N] add CNT_INFLOW_6m int NULL;
	set @s = @s + 'CNT_INFLOW_6m has been added into TXM_Batch_scoring_raw_N; ';
end;

if not exists (select * from sys.columns where [name]='CNT_INFLOW_12m' 
	and object_id = object_id('[dbo].[TXM_Batch_scoring_raw_N]'))
begin
	alter table [dbo].[TXM_Batch_scoring_raw_N] add CNT_INFLOW_12m int NULL;
	set @s = @s + 'CNT_INFLOW_12m has been added into TXM_Batch_scoring_raw_N; ';
end;

if not exists (select * from sys.columns where [name]='CNT_INFLOW_24m' 
	and object_id = object_id('[dbo].[TXM_Batch_scoring_raw_N]'))
begin
	alter table [dbo].[TXM_Batch_scoring_raw_N] add CNT_INFLOW_24m int NULL;
	set @s = @s + 'CNT_INFLOW_24m has been added into TXM_Batch_scoring_raw_N; ';
end;

if not exists (select * from sys.columns where [name]='SUM_OUTFLOW_1d' 
	and object_id = object_id('[dbo].[TXM_Batch_scoring_raw_N]'))
begin
	alter table [dbo].[TXM_Batch_scoring_raw_N] add SUM_OUTFLOW_1d numeric(15,2) NULL;
	set @s = @s + 'SUM_OUTFLOW_1d has been added into TXM_Batch_scoring_raw_N; ';
end;

if not exists (select * from sys.columns where [name]='SUM_OUTFLOW_3d' 
	and object_id = object_id('[dbo].[TXM_Batch_scoring_raw_N]'))
begin
	alter table [dbo].[TXM_Batch_scoring_raw_N] add SUM_OUTFLOW_3d numeric(15,2) NULL;
	set @s = @s + 'SUM_OUTFLOW_3d has been added into TXM_Batch_scoring_raw_N; ';
end;

if not exists (select * from sys.columns where [name]='SUM_OUTFLOW_7d' 
	and object_id = object_id('[dbo].[TXM_Batch_scoring_raw_N]'))
begin
	alter table [dbo].[TXM_Batch_scoring_raw_N] add SUM_OUTFLOW_7d numeric(15,2) NULL;
	set @s = @s + 'SUM_OUTFLOW_7d has been added into TXM_Batch_scoring_raw_N; ';
end;

if not exists (select * from sys.columns where [name]='SUM_OUTFLOW_10d' 
	and object_id = object_id('[dbo].[TXM_Batch_scoring_raw_N]'))
begin
	alter table [dbo].[TXM_Batch_scoring_raw_N] add SUM_OUTFLOW_10d numeric(15,2) NULL;
	set @s = @s + 'SUM_OUTFLOW_10d has been added into TXM_Batch_scoring_raw_N; ';
end;

if not exists (select * from sys.columns where [name]='SUM_OUTFLOW_30d' 
	and object_id = object_id('[dbo].[TXM_Batch_scoring_raw_N]'))
begin
	alter table [dbo].[TXM_Batch_scoring_raw_N] add SUM_OUTFLOW_30d numeric(15,2) NULL;
	set @s = @s + 'SUM_OUTFLOW_30d has been added into TXM_Batch_scoring_raw_N; ';
end;

if not exists (select * from sys.columns where [name]='SUM_OUTFLOW_3m' 
	and object_id = object_id('[dbo].[TXM_Batch_scoring_raw_N]'))
begin
	alter table [dbo].[TXM_Batch_scoring_raw_N] add SUM_OUTFLOW_3m numeric(15,2) NULL;
	set @s = @s + 'SUM_OUTFLOW_3m has been added into TXM_Batch_scoring_raw_N; ';
end;

if not exists (select * from sys.columns where [name]='SUM_OUTFLOW_6m' 
	and object_id = object_id('[dbo].[TXM_Batch_scoring_raw_N]'))
begin
	alter table [dbo].[TXM_Batch_scoring_raw_N] add SUM_OUTFLOW_6m numeric(15,2) NULL;
	set @s = @s + 'SUM_OUTFLOW_6m has been added into TXM_Batch_scoring_raw_N; ';
end;

if not exists (select * from sys.columns where [name]='SUM_OUTFLOW_12m' 
	and object_id = object_id('[dbo].[TXM_Batch_scoring_raw_N]'))
begin
	alter table [dbo].[TXM_Batch_scoring_raw_N] add SUM_OUTFLOW_12m numeric(15,2) NULL;
	set @s = @s + 'SUM_OUTFLOW_12m has been added into TXM_Batch_scoring_raw_N; ';
end;

if not exists (select * from sys.columns where [name]='SUM_OUTFLOW_24m' 
	and object_id = object_id('[dbo].[TXM_Batch_scoring_raw_N]'))
begin
	alter table [dbo].[TXM_Batch_scoring_raw_N] add SUM_OUTFLOW_24m numeric(15,2) NULL;
	set @s = @s + 'SUM_OUTFLOW_24m has been added into TXM_Batch_scoring_raw_N; ';
end;

if not exists (select * from sys.columns where [name]='CNT_OUTFLOW_1d' 
	and object_id = object_id('[dbo].[TXM_Batch_scoring_raw_N]'))
begin
	alter table [dbo].[TXM_Batch_scoring_raw_N] add CNT_OUTFLOW_1d int NULL;
	set @s = @s + 'CNT_OUTFLOW_1d has been added into TXM_Batch_scoring_raw_N; ';
end;

if not exists (select * from sys.columns where [name]='CNT_OUTFLOW_3d' 
	and object_id = object_id('[dbo].[TXM_Batch_scoring_raw_N]'))
begin
	alter table [dbo].[TXM_Batch_scoring_raw_N] add CNT_OUTFLOW_3d int NULL;
	set @s = @s + 'CNT_OUTFLOW_3d has been added into TXM_Batch_scoring_raw_N; ';
end;

if not exists (select * from sys.columns where [name]='CNT_OUTFLOW_7d' 
	and object_id = object_id('[dbo].[TXM_Batch_scoring_raw_N]'))
begin
	alter table [dbo].[TXM_Batch_scoring_raw_N] add CNT_OUTFLOW_7d int NULL;
	set @s = @s + 'CNT_OUTFLOW_7d has been added into TXM_Batch_scoring_raw_N; ';
end;

if not exists (select * from sys.columns where [name]='CNT_OUTFLOW_10d' 
	and object_id = object_id('[dbo].[TXM_Batch_scoring_raw_N]'))
begin
	alter table [dbo].[TXM_Batch_scoring_raw_N] add CNT_OUTFLOW_10d int NULL;
	set @s = @s + 'CNT_OUTFLOW_10d has been added into TXM_Batch_scoring_raw_N; ';
end;

if not exists (select * from sys.columns where [name]='CNT_OUTFLOW_30d' 
	and object_id = object_id('[dbo].[TXM_Batch_scoring_raw_N]'))
begin
	alter table [dbo].[TXM_Batch_scoring_raw_N] add CNT_OUTFLOW_30d int NULL;
	set @s = @s + 'CNT_OUTFLOW_30d has been added into TXM_Batch_scoring_raw_N; ';
end;

if not exists (select * from sys.columns where [name]='CNT_OUTFLOW_3m' 
	and object_id = object_id('[dbo].[TXM_Batch_scoring_raw_N]'))
begin
	alter table [dbo].[TXM_Batch_scoring_raw_N] add CNT_OUTFLOW_3m int NULL;
	set @s = @s + 'CNT_OUTFLOW_3m has been added into TXM_Batch_scoring_raw_N; ';
end;

if not exists (select * from sys.columns where [name]='CNT_OUTFLOW_6m' 
	and object_id = object_id('[dbo].[TXM_Batch_scoring_raw_N]'))
begin
	alter table [dbo].[TXM_Batch_scoring_raw_N] add CNT_OUTFLOW_6m int NULL;
	set @s = @s + 'CNT_OUTFLOW_6m has been added into TXM_Batch_scoring_raw_N; ';
end;

if not exists (select * from sys.columns where [name]='CNT_OUTFLOW_12m' 
	and object_id = object_id('[dbo].[TXM_Batch_scoring_raw_N]'))
begin
	alter table [dbo].[TXM_Batch_scoring_raw_N] add CNT_OUTFLOW_12m int NULL;
	set @s = @s + 'CNT_OUTFLOW_12m has been added into TXM_Batch_scoring_raw_N; ';
end;

if not exists (select * from sys.columns where [name]='CNT_OUTFLOW_24m' 
	and object_id = object_id('[dbo].[TXM_Batch_scoring_raw_N]'))
begin
	alter table [dbo].[TXM_Batch_scoring_raw_N] add CNT_OUTFLOW_24m int NULL;
	set @s = @s + 'CNT_OUTFLOW_24m has been added into TXM_Batch_scoring_raw_N; ';
end;

if not exists (select * from sys.columns where [name]='SUM_INFLOW_Dubious_3m' 
	and object_id = object_id('[dbo].[TXM_Batch_scoring_raw_N]'))
begin
	alter table [dbo].[TXM_Batch_scoring_raw_N] add SUM_INFLOW_Dubious_3m numeric(15,2) NULL;
	set @s = @s + 'SUM_INFLOW_Dubious_3m has been added into TXM_Batch_scoring_raw_N; ';
end;

if not exists (select * from sys.columns where [name]='CNT_INFLOW_Dubious_3m' 
	and object_id = object_id('[dbo].[TXM_Batch_scoring_raw_N]'))
begin
	alter table [dbo].[TXM_Batch_scoring_raw_N] add CNT_INFLOW_Dubious_3m int NULL;
	set @s = @s + 'CNT_INFLOW_Dubious_3m has been added into TXM_Batch_scoring_raw_N; ';
end;

if not exists (select * from sys.columns where [name]='SUM_INFLOW_CRYPTO_30d' 
	and object_id = object_id('[dbo].[TXM_Batch_scoring_raw_N]'))
begin
	alter table [dbo].[TXM_Batch_scoring_raw_N] add SUM_INFLOW_CRYPTO_30d numeric(15,2) NULL;
	set @s = @s + 'SUM_INFLOW_CRYPTO_30d has been added into TXM_Batch_scoring_raw_N; ';
end;

if not exists (select * from sys.columns where [name]='CNT_INFLOW_CRYPTO_30d' 
	and object_id = object_id('[dbo].[TXM_Batch_scoring_raw_N]'))
begin
	alter table [dbo].[TXM_Batch_scoring_raw_N] add CNT_INFLOW_CRYPTO_30d int NULL;
	set @s = @s + 'CNT_INFLOW_CRYPTO_30d has been added into TXM_Batch_scoring_raw_N; ';
end;

if not exists (select * from sys.columns where [name]='SUM_OUTFLOW_CRYPTO_30d' 
	and object_id = object_id('[dbo].[TXM_Batch_scoring_raw_N]'))
begin
	alter table [dbo].[TXM_Batch_scoring_raw_N] add SUM_OUTFLOW_CRYPTO_30d numeric(15,2) NULL;
	set @s = @s + 'SUM_OUTFLOW_CRYPTO_30d has been added into TXM_Batch_scoring_raw_N; ';
end;

if not exists (select * from sys.columns where [name]='CNT_OUTFLOW_CRYPTO_30d' 
	and object_id = object_id('[dbo].[TXM_Batch_scoring_raw_N]'))
begin
	alter table [dbo].[TXM_Batch_scoring_raw_N] add CNT_OUTFLOW_CRYPTO_30d int NULL;
	set @s = @s + 'CNT_OUTFLOW_CRYPTO_30d has been added into TXM_Batch_scoring_raw_N; ';
end;

if not exists (select * from sys.columns where [name]='SUM_OUTFLOW_CASH_30d' 
	and object_id = object_id('[dbo].[TXM_Batch_scoring_raw_N]'))
begin
	alter table [dbo].[TXM_Batch_scoring_raw_N] add SUM_OUTFLOW_CASH_30d numeric(15,2) NULL;
	set @s = @s + 'SUM_OUTFLOW_CASH_30d has been added into TXM_Batch_scoring_raw_N; ';
end;

if not exists (select * from sys.columns where [name]='CNT_OUTFLOW_CASH_30d' 
	and object_id = object_id('[dbo].[TXM_Batch_scoring_raw_N]'))
begin
	alter table [dbo].[TXM_Batch_scoring_raw_N] add CNT_OUTFLOW_CASH_30d int NULL;
	set @s = @s + 'CNT_OUTFLOW_CASH_30d has been added into TXM_Batch_scoring_raw_N; ';
end;

if not exists (select * from sys.columns where [name]='SUM_OUTFLOW_CASH_7d' 
	and object_id = object_id('[dbo].[TXM_Batch_scoring_raw_N]'))
begin
	alter table [dbo].[TXM_Batch_scoring_raw_N] add SUM_OUTFLOW_CASH_7d numeric(15,2) NULL;
	set @s = @s + 'SUM_OUTFLOW_CASH_7d has been added into TXM_Batch_scoring_raw_N; ';
end;

if not exists (select * from sys.columns where [name]='CNT_OUTFLOW_CASH_7d' 
	and object_id = object_id('[dbo].[TXM_Batch_scoring_raw_N]'))
begin
	alter table [dbo].[TXM_Batch_scoring_raw_N] add CNT_OUTFLOW_CASH_7d int NULL;
	set @s = @s + 'CNT_OUTFLOW_CASH_7d has been added into TXM_Batch_scoring_raw_N; ';
end;

if not exists (select * from sys.columns where [name]='SUM_OUTFLOW_CASH_3d' 
	and object_id = object_id('[dbo].[TXM_Batch_scoring_raw_N]'))
begin
	alter table [dbo].[TXM_Batch_scoring_raw_N] add SUM_OUTFLOW_CASH_3d numeric(15,2) NULL;
	set @s = @s + 'SUM_OUTFLOW_CASH_3d has been added into TXM_Batch_scoring_raw_N; ';
end;

if not exists (select * from sys.columns where [name]='CNT_OUTFLOW_CASH_3d' 
	and object_id = object_id('[dbo].[TXM_Batch_scoring_raw_N]'))
begin
	alter table [dbo].[TXM_Batch_scoring_raw_N] add CNT_OUTFLOW_CASH_3d int NULL;
	set @s = @s + 'CNT_OUTFLOW_CASH_3d has been added into TXM_Batch_scoring_raw_N; ';
end;

if not exists (select * from sys.columns where [name]='SUM_FOREIGN_INFLOW_3m' 
	and object_id = object_id('[dbo].[TXM_Batch_scoring_raw_N]'))
begin
	alter table [dbo].[TXM_Batch_scoring_raw_N] add SUM_FOREIGN_INFLOW_3m numeric(15,2) NULL;
	set @s = @s + 'SUM_FOREIGN_INFLOW_3m has been added into TXM_Batch_scoring_raw_N; ';
end;

if not exists (select * from sys.columns where [name]='SUM_FOREIGN_INFLOW_12m' 
	and object_id = object_id('[dbo].[TXM_Batch_scoring_raw_N]'))
begin
	alter table [dbo].[TXM_Batch_scoring_raw_N] add SUM_FOREIGN_INFLOW_12m numeric(15,2) NULL;
	set @s = @s + 'SUM_FOREIGN_INFLOW_12m has been added into TXM_Batch_scoring_raw_N; ';
end;

if not exists (select * from sys.columns where [name]='SUM_FOREIGN_OUTFLOW_3m' 
	and object_id = object_id('[dbo].[TXM_Batch_scoring_raw_N]'))
begin
	alter table [dbo].[TXM_Batch_scoring_raw_N] add SUM_FOREIGN_OUTFLOW_3m numeric(15,2) NULL;
	set @s = @s + 'SUM_FOREIGN_OUTFLOW_3m has been added into TXM_Batch_scoring_raw_N; ';
end;

if not exists (select * from sys.columns where [name]='SUM_FOREIGN_OUTFLOW_12m' 
	and object_id = object_id('[dbo].[TXM_Batch_scoring_raw_N]'))
begin
	alter table [dbo].[TXM_Batch_scoring_raw_N] add SUM_FOREIGN_OUTFLOW_12m numeric(15,2) NULL;
	set @s = @s + 'SUM_FOREIGN_OUTFLOW_12m has been added into TXM_Batch_scoring_raw_N; ';
end;

if not exists (select * from sys.columns where [name]='CNT_SMALL_INFLOWS_30d' 
	and object_id = object_id('[dbo].[TXM_Batch_scoring_raw_N]'))
begin
	alter table [dbo].[TXM_Batch_scoring_raw_N] add CNT_SMALL_INFLOWS_30d int NULL;
	set @s = @s + 'CNT_SMALL_INFLOWS_30d has been added into TXM_Batch_scoring_raw_N; ';
end;

if not exists (select * from sys.columns where [name]='CNT_SMALL_OUTFLOWS_30d' 
	and object_id = object_id('[dbo].[TXM_Batch_scoring_raw_N]'))
begin
	alter table [dbo].[TXM_Batch_scoring_raw_N] add CNT_SMALL_OUTFLOWS_30d int NULL;
	set @s = @s + 'CNT_SMALL_OUTFLOWS_30d has been added into TXM_Batch_scoring_raw_N; ';
end;

if not exists (select * from sys.columns where [name]='SUM_RETURNDEBIT_30d' 
	and object_id = object_id('[dbo].[TXM_Batch_scoring_raw_N]'))
begin
	alter table [dbo].[TXM_Batch_scoring_raw_N] add SUM_RETURNDEBIT_30d numeric(15,2) NULL;
	set @s = @s + 'SUM_RETURNDEBIT_30d has been added into TXM_Batch_scoring_raw_N; ';
end;

if not exists (select * from sys.columns where [name]='CNT_RETURNDEBIT_30d' 
	and object_id = object_id('[dbo].[TXM_Batch_scoring_raw_N]'))
begin
	alter table [dbo].[TXM_Batch_scoring_raw_N] add CNT_RETURNDEBIT_30d int NULL;
	set @s = @s + 'CNT_RETURNDEBIT_30d has been added into TXM_Batch_scoring_raw_N; ';
end;

if not exists (select * from sys.columns where [name]='SUM_ChequeDeposit_3d' 
	and object_id = object_id('[dbo].[TXM_Batch_scoring_raw_N]'))
begin
	alter table [dbo].[TXM_Batch_scoring_raw_N] add SUM_ChequeDeposit_3d numeric(15,2) NULL;
	set @s = @s + 'SUM_ChequeDeposit_3d has been added into TXM_Batch_scoring_raw_N; ';
end;

if not exists (select * from sys.columns where [name]='SUM_INFLOW_3RD_PARTY_14d' 
	and object_id = object_id('[dbo].[TXM_Batch_scoring_raw_N]'))
begin
	alter table [dbo].[TXM_Batch_scoring_raw_N] add SUM_INFLOW_3RD_PARTY_14d numeric(15,2) NULL;
	set @s = @s + 'SUM_INFLOW_3RD_PARTY_14d has been added into TXM_Batch_scoring_raw_N; ';
end;

if not exists (select * from sys.columns where [name]='CNT_INFLOW_3RD_PARTY_14d' 
	and object_id = object_id('[dbo].[TXM_Batch_scoring_raw_N]'))
begin
	alter table [dbo].[TXM_Batch_scoring_raw_N] add CNT_INFLOW_3RD_PARTY_14d int NULL;
	set @s = @s + 'CNT_INFLOW_3RD_PARTY_14d has been added into TXM_Batch_scoring_raw_N; ';
end;

if not exists (select * from sys.columns where [name]='SUM_INFLOW_MISMATCH_RECIPIENT_3d' 
	and object_id = object_id('[dbo].[TXM_Batch_scoring_raw_N]'))
begin
	alter table [dbo].[TXM_Batch_scoring_raw_N] add SUM_INFLOW_MISMATCH_RECIPIENT_3d numeric(15,2) NULL;
	set @s = @s + 'SUM_INFLOW_MISMATCH_RECIPIENT_3d has been added into TXM_Batch_scoring_raw_N; ';
end;

if not exists (select * from sys.columns where [name]='CNT_INFLOW_MISMATCH_RECIPIENT_3d' 
	and object_id = object_id('[dbo].[TXM_Batch_scoring_raw_N]'))
begin
	alter table [dbo].[TXM_Batch_scoring_raw_N] add CNT_INFLOW_MISMATCH_RECIPIENT_3d int NULL;
	set @s = @s + 'CNT_INFLOW_MISMATCH_RECIPIENT_3d has been added into TXM_Batch_scoring_raw_N; ';
end;

if not exists (select * from sys.columns where [name]='SUM_INFLOW_LOAN_30d' 
	and object_id = object_id('[dbo].[TXM_Batch_scoring_raw_N]'))
begin
	alter table [dbo].[TXM_Batch_scoring_raw_N] add SUM_INFLOW_LOAN_30d numeric(15,2) NULL;
	set @s = @s + 'SUM_INFLOW_LOAN_30d has been added into TXM_Batch_scoring_raw_N; ';
end;

if not exists (select * from sys.columns where [name]='CNT_INFLOW_LOAN_30d' 
	and object_id = object_id('[dbo].[TXM_Batch_scoring_raw_N]'))
begin
	alter table [dbo].[TXM_Batch_scoring_raw_N] add CNT_INFLOW_LOAN_30d int NULL;
	set @s = @s + 'CNT_INFLOW_LOAN_30d has been added into TXM_Batch_scoring_raw_N; ';
end;

if not exists (select * from sys.columns where [name]='SUM_GAMBLING_7d' 
	and object_id = object_id('[dbo].[TXM_Batch_scoring_raw_N]'))
begin
	alter table [dbo].[TXM_Batch_scoring_raw_N] add SUM_GAMBLING_7d numeric(15,2) NULL;
	set @s = @s + 'SUM_GAMBLING_7d has been added into TXM_Batch_scoring_raw_N; ';
end;

if not exists (select * from sys.columns where [name]='CNT_GAMBLING_7d' 
	and object_id = object_id('[dbo].[TXM_Batch_scoring_raw_N]'))
begin
	alter table [dbo].[TXM_Batch_scoring_raw_N] add CNT_GAMBLING_7d int NULL;
	set @s = @s + 'CNT_GAMBLING_7d has been added into TXM_Batch_scoring_raw_N; ';
end;

if not exists (select * from sys.columns where [name]='SUM_GAMBLING_30d' 
	and object_id = object_id('[dbo].[TXM_Batch_scoring_raw_N]'))
begin
	alter table [dbo].[TXM_Batch_scoring_raw_N] add SUM_GAMBLING_30d numeric(15,2) NULL;
	set @s = @s + 'SUM_GAMBLING_30d has been added into TXM_Batch_scoring_raw_N; ';
end;

if not exists (select * from sys.columns where [name]='CNT_GAMBLING_30d' 
	and object_id = object_id('[dbo].[TXM_Batch_scoring_raw_N]'))
begin
	alter table [dbo].[TXM_Batch_scoring_raw_N] add CNT_GAMBLING_30d int NULL;
	set @s = @s + 'CNT_GAMBLING_30d has been added into TXM_Batch_scoring_raw_N; ';
end;

if not exists (select * from sys.columns where [name]='SUM_GAMBLING_3m' 
	and object_id = object_id('[dbo].[TXM_Batch_scoring_raw_N]'))
begin
	alter table [dbo].[TXM_Batch_scoring_raw_N] add SUM_GAMBLING_3m numeric(15,2) NULL;
	set @s = @s + 'SUM_GAMBLING_3m has been added into TXM_Batch_scoring_raw_N; ';
end;

if not exists (select * from sys.columns where [name]='CNT_GAMBLING_3m' 
	and object_id = object_id('[dbo].[TXM_Batch_scoring_raw_N]'))
begin
	alter table [dbo].[TXM_Batch_scoring_raw_N] add CNT_GAMBLING_3m int NULL;
	set @s = @s + 'CNT_GAMBLING_3m has been added into TXM_Batch_scoring_raw_N; ';
end;

if not exists (select * from sys.columns where [name]='SUM_INOUT_1d' 
	and object_id = object_id('[dbo].[TXM_Batch_scoring_raw_N]'))
begin
	alter table [dbo].[TXM_Batch_scoring_raw_N] add SUM_INOUT_1d numeric(15,2) NULL;
	set @s = @s + 'SUM_INOUT_1d has been added into TXM_Batch_scoring_raw_N; ';
end;

if not exists (select * from sys.columns where [name]='SUM_INOUT_3d' 
	and object_id = object_id('[dbo].[TXM_Batch_scoring_raw_N]'))
begin
	alter table [dbo].[TXM_Batch_scoring_raw_N] add SUM_INOUT_3d numeric(15,2) NULL;
	set @s = @s + 'SUM_INOUT_3d has been added into TXM_Batch_scoring_raw_N; ';
end;

if not exists (select * from sys.columns where [name]='SUM_INOUT_7d' 
	and object_id = object_id('[dbo].[TXM_Batch_scoring_raw_N]'))
begin
	alter table [dbo].[TXM_Batch_scoring_raw_N] add SUM_INOUT_7d numeric(15,2) NULL;
	set @s = @s + 'SUM_INOUT_7d has been added into TXM_Batch_scoring_raw_N; ';
end;

if not exists (select * from sys.columns where [name]='SUM_INOUT_10d' 
	and object_id = object_id('[dbo].[TXM_Batch_scoring_raw_N]'))
begin
	alter table [dbo].[TXM_Batch_scoring_raw_N] add SUM_INOUT_10d numeric(15,2) NULL;
	set @s = @s + 'SUM_INOUT_10d has been added into TXM_Batch_scoring_raw_N; ';
end;

if not exists (select * from sys.columns where [name]='SUM_INOUT_30d' 
	and object_id = object_id('[dbo].[TXM_Batch_scoring_raw_N]'))
begin
	alter table [dbo].[TXM_Batch_scoring_raw_N] add SUM_INOUT_30d numeric(15,2) NULL;
	set @s = @s + 'SUM_INOUT_30d has been added into TXM_Batch_scoring_raw_N; ';
end;

if not exists (select * from sys.columns where [name]='SUM_INOUT_3m' 
	and object_id = object_id('[dbo].[TXM_Batch_scoring_raw_N]'))
begin
	alter table [dbo].[TXM_Batch_scoring_raw_N] add SUM_INOUT_3m numeric(15,2) NULL;
	set @s = @s + 'SUM_INOUT_3m has been added into TXM_Batch_scoring_raw_N; ';
end;

if not exists (select * from sys.columns where [name]='SUM_INOUT_6m' 
	and object_id = object_id('[dbo].[TXM_Batch_scoring_raw_N]'))
begin
	alter table [dbo].[TXM_Batch_scoring_raw_N] add SUM_INOUT_6m numeric(15,2) NULL;
	set @s = @s + 'SUM_INOUT_6m has been added into TXM_Batch_scoring_raw_N; ';
end;

if not exists (select * from sys.columns where [name]='SUM_INOUT_12m' 
	and object_id = object_id('[dbo].[TXM_Batch_scoring_raw_N]'))
begin
	alter table [dbo].[TXM_Batch_scoring_raw_N] add SUM_INOUT_12m numeric(15,2) NULL;
	set @s = @s + 'SUM_INOUT_12m has been added into TXM_Batch_scoring_raw_N; ';
end;

if not exists (select * from sys.columns where [name]='SUM_INOUT_24m' 
	and object_id = object_id('[dbo].[TXM_Batch_scoring_raw_N]'))
begin
	alter table [dbo].[TXM_Batch_scoring_raw_N] add SUM_INOUT_24m numeric(15,2) NULL;
	set @s = @s + 'SUM_INOUT_24m has been added into TXM_Batch_scoring_raw_N; ';
end;

if not exists (select * from sys.columns where [name]='CNT_INOUT_1d' 
	and object_id = object_id('[dbo].[TXM_Batch_scoring_raw_N]'))
begin
	alter table [dbo].[TXM_Batch_scoring_raw_N] add CNT_INOUT_1d int NULL;
	set @s = @s + 'CNT_INOUT_1d has been added into TXM_Batch_scoring_raw_N; ';
end;

if not exists (select * from sys.columns where [name]='CNT_INOUT_3d' 
	and object_id = object_id('[dbo].[TXM_Batch_scoring_raw_N]'))
begin
	alter table [dbo].[TXM_Batch_scoring_raw_N] add CNT_INOUT_3d int NULL;
	set @s = @s + 'CNT_INOUT_3d has been added into TXM_Batch_scoring_raw_N; ';
end;

if not exists (select * from sys.columns where [name]='CNT_INOUT_7d' 
	and object_id = object_id('[dbo].[TXM_Batch_scoring_raw_N]'))
begin
	alter table [dbo].[TXM_Batch_scoring_raw_N] add CNT_INOUT_7d int NULL;
	set @s = @s + 'CNT_INOUT_7d has been added into TXM_Batch_scoring_raw_N; ';
end;

if not exists (select * from sys.columns where [name]='CNT_INOUT_10d' 
	and object_id = object_id('[dbo].[TXM_Batch_scoring_raw_N]'))
begin
	alter table [dbo].[TXM_Batch_scoring_raw_N] add CNT_INOUT_10d int NULL;
	set @s = @s + 'CNT_INOUT_10d has been added into TXM_Batch_scoring_raw_N; ';
end;

if not exists (select * from sys.columns where [name]='CNT_INOUT_30d' 
	and object_id = object_id('[dbo].[TXM_Batch_scoring_raw_N]'))
begin
	alter table [dbo].[TXM_Batch_scoring_raw_N] add CNT_INOUT_30d int NULL;
	set @s = @s + 'CNT_INOUT_30d has been added into TXM_Batch_scoring_raw_N; ';
end;

if not exists (select * from sys.columns where [name]='CNT_INOUT_3m' 
	and object_id = object_id('[dbo].[TXM_Batch_scoring_raw_N]'))
begin
	alter table [dbo].[TXM_Batch_scoring_raw_N] add CNT_INOUT_3m int NULL;
	set @s = @s + 'CNT_INOUT_3m has been added into TXM_Batch_scoring_raw_N; ';
end;

if not exists (select * from sys.columns where [name]='CNT_INOUT_6m' 
	and object_id = object_id('[dbo].[TXM_Batch_scoring_raw_N]'))
begin
	alter table [dbo].[TXM_Batch_scoring_raw_N] add CNT_INOUT_6m int NULL;
	set @s = @s + 'CNT_INOUT_6m has been added into TXM_Batch_scoring_raw_N; ';
end;

if not exists (select * from sys.columns where [name]='CNT_INOUT_12m' 
	and object_id = object_id('[dbo].[TXM_Batch_scoring_raw_N]'))
begin
	alter table [dbo].[TXM_Batch_scoring_raw_N] add CNT_INOUT_12m int NULL;
	set @s = @s + 'CNT_INOUT_12m has been added into TXM_Batch_scoring_raw_N; ';
end;

if not exists (select * from sys.columns where [name]='CNT_INOUT_24m' 
	and object_id = object_id('[dbo].[TXM_Batch_scoring_raw_N]'))
begin
	alter table [dbo].[TXM_Batch_scoring_raw_N] add CNT_INOUT_24m int NULL;
	set @s = @s + 'CNT_INOUT_24m has been added into TXM_Batch_scoring_raw_N; ';
end;

if not exists (select * from sys.columns where [name]='SUM_FOREIGN_INOUT_3m' 
	and object_id = object_id('[dbo].[TXM_Batch_scoring_raw_N]'))
begin
	alter table [dbo].[TXM_Batch_scoring_raw_N] add SUM_FOREIGN_INOUT_3m numeric(15,2) NULL;
	set @s = @s + 'SUM_FOREIGN_INOUT_3m has been added into TXM_Batch_scoring_raw_N; ';
end;

if not exists (select * from sys.columns where [name]='SUM_FOREIGN_INOUT_12m' 
	and object_id = object_id('[dbo].[TXM_Batch_scoring_raw_N]'))
begin
	alter table [dbo].[TXM_Batch_scoring_raw_N] add SUM_FOREIGN_INOUT_12m numeric(15,2) NULL;
	set @s = @s + 'SUM_FOREIGN_INOUT_12m has been added into TXM_Batch_scoring_raw_N; ';
end;

if not exists (select * from sys.columns where [name]='AVG_INFLOW_1d' 
	and object_id = object_id('[dbo].[TXM_Batch_scoring_raw_N]'))
begin
	alter table [dbo].[TXM_Batch_scoring_raw_N] add AVG_INFLOW_1d numeric(15,2) NULL;
	set @s = @s + 'AVG_INFLOW_1d has been added into TXM_Batch_scoring_raw_N; ';
end;

if not exists (select * from sys.columns where [name]='AVG_INFLOW_3d' 
	and object_id = object_id('[dbo].[TXM_Batch_scoring_raw_N]'))
begin
	alter table [dbo].[TXM_Batch_scoring_raw_N] add AVG_INFLOW_3d numeric(15,2) NULL;
	set @s = @s + 'AVG_INFLOW_3d has been added into TXM_Batch_scoring_raw_N; ';
end;

if not exists (select * from sys.columns where [name]='AVG_INFLOW_7d' 
	and object_id = object_id('[dbo].[TXM_Batch_scoring_raw_N]'))
begin
	alter table [dbo].[TXM_Batch_scoring_raw_N] add AVG_INFLOW_7d numeric(15,2) NULL;
	set @s = @s + 'AVG_INFLOW_7d has been added into TXM_Batch_scoring_raw_N; ';
end;

if not exists (select * from sys.columns where [name]='AVG_INFLOW_10d' 
	and object_id = object_id('[dbo].[TXM_Batch_scoring_raw_N]'))
begin
	alter table [dbo].[TXM_Batch_scoring_raw_N] add AVG_INFLOW_10d numeric(15,2) NULL;
	set @s = @s + 'AVG_INFLOW_10d has been added into TXM_Batch_scoring_raw_N; ';
end;

if not exists (select * from sys.columns where [name]='AVG_INFLOW_30d' 
	and object_id = object_id('[dbo].[TXM_Batch_scoring_raw_N]'))
begin
	alter table [dbo].[TXM_Batch_scoring_raw_N] add AVG_INFLOW_30d numeric(15,2) NULL;
	set @s = @s + 'AVG_INFLOW_30d has been added into TXM_Batch_scoring_raw_N; ';
end;

if not exists (select * from sys.columns where [name]='AVG_INFLOW_3m' 
	and object_id = object_id('[dbo].[TXM_Batch_scoring_raw_N]'))
begin
	alter table [dbo].[TXM_Batch_scoring_raw_N] add AVG_INFLOW_3m numeric(15,2) NULL;
	set @s = @s + 'AVG_INFLOW_3m has been added into TXM_Batch_scoring_raw_N; ';
end;

if not exists (select * from sys.columns where [name]='AVG_INFLOW_6m' 
	and object_id = object_id('[dbo].[TXM_Batch_scoring_raw_N]'))
begin
	alter table [dbo].[TXM_Batch_scoring_raw_N] add AVG_INFLOW_6m numeric(15,2) NULL;
	set @s = @s + 'AVG_INFLOW_6m has been added into TXM_Batch_scoring_raw_N; ';
end;

if not exists (select * from sys.columns where [name]='AVG_INFLOW_12m' 
	and object_id = object_id('[dbo].[TXM_Batch_scoring_raw_N]'))
begin
	alter table [dbo].[TXM_Batch_scoring_raw_N] add AVG_INFLOW_12m numeric(15,2) NULL;
	set @s = @s + 'AVG_INFLOW_12m has been added into TXM_Batch_scoring_raw_N; ';
end;

if not exists (select * from sys.columns where [name]='AVG_INFLOW_24m' 
	and object_id = object_id('[dbo].[TXM_Batch_scoring_raw_N]'))
begin
	alter table [dbo].[TXM_Batch_scoring_raw_N] add AVG_INFLOW_24m numeric(15,2) NULL;
	set @s = @s + 'AVG_INFLOW_24m has been added into TXM_Batch_scoring_raw_N; ';
end;

if not exists (select * from sys.columns where [name]='AVG_OUTFLOW_1d' 
	and object_id = object_id('[dbo].[TXM_Batch_scoring_raw_N]'))
begin
	alter table [dbo].[TXM_Batch_scoring_raw_N] add AVG_OUTFLOW_1d numeric(15,2) NULL;
	set @s = @s + 'AVG_OUTFLOW_1d has been added into TXM_Batch_scoring_raw_N; ';
end;

if not exists (select * from sys.columns where [name]='AVG_OUTFLOW_3d' 
	and object_id = object_id('[dbo].[TXM_Batch_scoring_raw_N]'))
begin
	alter table [dbo].[TXM_Batch_scoring_raw_N] add AVG_OUTFLOW_3d numeric(15,2) NULL;
	set @s = @s + 'AVG_OUTFLOW_3d has been added into TXM_Batch_scoring_raw_N; ';
end;

if not exists (select * from sys.columns where [name]='AVG_OUTFLOW_7d' 
	and object_id = object_id('[dbo].[TXM_Batch_scoring_raw_N]'))
begin
	alter table [dbo].[TXM_Batch_scoring_raw_N] add AVG_OUTFLOW_7d numeric(15,2) NULL;
	set @s = @s + 'AVG_OUTFLOW_7d has been added into TXM_Batch_scoring_raw_N; ';
end;

if not exists (select * from sys.columns where [name]='AVG_OUTFLOW_10d' 
	and object_id = object_id('[dbo].[TXM_Batch_scoring_raw_N]'))
begin
	alter table [dbo].[TXM_Batch_scoring_raw_N] add AVG_OUTFLOW_10d numeric(15,2) NULL;
	set @s = @s + 'AVG_OUTFLOW_10d has been added into TXM_Batch_scoring_raw_N; ';
end;

if not exists (select * from sys.columns where [name]='AVG_OUTFLOW_30d' 
	and object_id = object_id('[dbo].[TXM_Batch_scoring_raw_N]'))
begin
	alter table [dbo].[TXM_Batch_scoring_raw_N] add AVG_OUTFLOW_30d numeric(15,2) NULL;
	set @s = @s + 'AVG_OUTFLOW_30d has been added into TXM_Batch_scoring_raw_N; ';
end;

if not exists (select * from sys.columns where [name]='AVG_OUTFLOW_3m' 
	and object_id = object_id('[dbo].[TXM_Batch_scoring_raw_N]'))
begin
	alter table [dbo].[TXM_Batch_scoring_raw_N] add AVG_OUTFLOW_3m numeric(15,2) NULL;
	set @s = @s + 'AVG_OUTFLOW_3m has been added into TXM_Batch_scoring_raw_N; ';
end;

if not exists (select * from sys.columns where [name]='AVG_OUTFLOW_6m' 
	and object_id = object_id('[dbo].[TXM_Batch_scoring_raw_N]'))
begin
	alter table [dbo].[TXM_Batch_scoring_raw_N] add AVG_OUTFLOW_6m numeric(15,2) NULL;
	set @s = @s + 'AVG_OUTFLOW_6m has been added into TXM_Batch_scoring_raw_N; ';
end;

if not exists (select * from sys.columns where [name]='AVG_OUTFLOW_12m' 
	and object_id = object_id('[dbo].[TXM_Batch_scoring_raw_N]'))
begin
	alter table [dbo].[TXM_Batch_scoring_raw_N] add AVG_OUTFLOW_12m numeric(15,2) NULL;
	set @s = @s + 'AVG_OUTFLOW_12m has been added into TXM_Batch_scoring_raw_N; ';
end;

if not exists (select * from sys.columns where [name]='AVG_OUTFLOW_24m' 
	and object_id = object_id('[dbo].[TXM_Batch_scoring_raw_N]'))
begin
	alter table [dbo].[TXM_Batch_scoring_raw_N] add AVG_OUTFLOW_24m numeric(15,2) NULL;
	set @s = @s + 'AVG_OUTFLOW_24m has been added into TXM_Batch_scoring_raw_N; ';
end;

if not exists (select * from sys.columns where [name]='MAX_KD_TOTAL_SALDO_3d' 
	and object_id = object_id('[dbo].[TXM_Batch_scoring_raw_N]'))
begin
	alter table [dbo].[TXM_Batch_scoring_raw_N] add MAX_KD_TOTAL_SALDO_3d numeric(15,2) NULL;
	set @s = @s + 'MAX_KD_TOTAL_SALDO_3d has been added into TXM_Batch_scoring_raw_N; ';
end;

if not exists (select * from sys.columns where [name]='MAX_KD_TOTAL_SALDO_30d' 
	and object_id = object_id('[dbo].[TXM_Batch_scoring_raw_N]'))
begin
	alter table [dbo].[TXM_Batch_scoring_raw_N] add MAX_KD_TOTAL_SALDO_30d numeric(15,2) NULL;
	set @s = @s + 'MAX_KD_TOTAL_SALDO_30d has been added into TXM_Batch_scoring_raw_N; ';
end;

if not exists (select * from sys.columns where [name]='SUM_KD_CURRENT_SALDO' 
	and object_id = object_id('[dbo].[TXM_Batch_scoring_raw_N]'))
begin
	alter table [dbo].[TXM_Batch_scoring_raw_N] add SUM_KD_CURRENT_SALDO numeric(15,2) NULL;
	set @s = @s + 'SUM_KD_CURRENT_SALDO has been added into TXM_Batch_scoring_raw_N; ';
end;

if not exists (select * from sys.columns where [name]='SUM_KD_SAVINGS_SALDO' 
	and object_id = object_id('[dbo].[TXM_Batch_scoring_raw_N]'))
begin
	alter table [dbo].[TXM_Batch_scoring_raw_N] add SUM_KD_SAVINGS_SALDO numeric(15,2) NULL;
	set @s = @s + 'SUM_KD_SAVINGS_SALDO has been added into TXM_Batch_scoring_raw_N; ';
end;

if not exists (select * from sys.columns where [name]='SUM_KD_LOAN_SALDO' 
	and object_id = object_id('[dbo].[TXM_Batch_scoring_raw_N]'))
begin
	alter table [dbo].[TXM_Batch_scoring_raw_N] add SUM_KD_LOAN_SALDO numeric(15,2) NULL;
	set @s = @s + 'SUM_KD_LOAN_SALDO has been added into TXM_Batch_scoring_raw_N; ';
end;

if not exists (select * from sys.columns where [name]='SUM_KD_CREDITCARD_SALDO' 
	and object_id = object_id('[dbo].[TXM_Batch_scoring_raw_N]'))
begin
	alter table [dbo].[TXM_Batch_scoring_raw_N] add SUM_KD_CREDITCARD_SALDO numeric(15,2) NULL;
	set @s = @s + 'SUM_KD_CREDITCARD_SALDO has been added into TXM_Batch_scoring_raw_N; ';
end;

if not exists (select * from sys.columns where [name]='SUM_KD_BUILDINGSAVINGS_SALDO' 
	and object_id = object_id('[dbo].[TXM_Batch_scoring_raw_N]'))
begin
	alter table [dbo].[TXM_Batch_scoring_raw_N] add SUM_KD_BUILDINGSAVINGS_SALDO numeric(15,2) NULL;
	set @s = @s + 'SUM_KD_BUILDINGSAVINGS_SALDO has been added into TXM_Batch_scoring_raw_N; ';
end;

if not exists (select * from sys.columns where [name]='SUM_KD_CAPITAL_SALDO' 
	and object_id = object_id('[dbo].[TXM_Batch_scoring_raw_N]'))
begin
	alter table [dbo].[TXM_Batch_scoring_raw_N] add SUM_KD_CAPITAL_SALDO numeric(15,2) NULL;
	set @s = @s + 'SUM_KD_CAPITAL_SALDO has been added into TXM_Batch_scoring_raw_N; ';
end;

if not exists (select * from sys.columns where [name]='SUM_KD_LIFEINSURANCE_SALDO' 
	and object_id = object_id('[dbo].[TXM_Batch_scoring_raw_N]'))
begin
	alter table [dbo].[TXM_Batch_scoring_raw_N] add SUM_KD_LIFEINSURANCE_SALDO numeric(15,2) NULL;
	set @s = @s + 'SUM_KD_LIFEINSURANCE_SALDO has been added into TXM_Batch_scoring_raw_N; ';
end;

if not exists (select * from sys.columns where [name]='SUM_KD_NONLIFEINSURANCE_SALDO' 
	and object_id = object_id('[dbo].[TXM_Batch_scoring_raw_N]'))
begin
	alter table [dbo].[TXM_Batch_scoring_raw_N] add SUM_KD_NONLIFEINSURANCE_SALDO numeric(15,2) NULL;
	set @s = @s + 'SUM_KD_NONLIFEINSURANCE_SALDO has been added into TXM_Batch_scoring_raw_N; ';
end;

if not exists (select * from sys.columns where [name]='CNT_KD_CURRENT_SALDO' 
	and object_id = object_id('[dbo].[TXM_Batch_scoring_raw_N]'))
begin
	alter table [dbo].[TXM_Batch_scoring_raw_N] add CNT_KD_CURRENT_SALDO int NULL;
	set @s = @s + 'CNT_KD_CURRENT_SALDO has been added into TXM_Batch_scoring_raw_N; ';
end;

if not exists (select * from sys.columns where [name]='CNT_KD_SAVINGS_SALDO' 
	and object_id = object_id('[dbo].[TXM_Batch_scoring_raw_N]'))
begin
	alter table [dbo].[TXM_Batch_scoring_raw_N] add CNT_KD_SAVINGS_SALDO int NULL;
	set @s = @s + 'CNT_KD_SAVINGS_SALDO has been added into TXM_Batch_scoring_raw_N; ';
end;

if not exists (select * from sys.columns where [name]='CNT_KD_LOAN_SALDO' 
	and object_id = object_id('[dbo].[TXM_Batch_scoring_raw_N]'))
begin
	alter table [dbo].[TXM_Batch_scoring_raw_N] add CNT_KD_LOAN_SALDO int NULL;
	set @s = @s + 'CNT_KD_LOAN_SALDO has been added into TXM_Batch_scoring_raw_N; ';
end;

if not exists (select * from sys.columns where [name]='CNT_KD_CREDITCARD_SALDO' 
	and object_id = object_id('[dbo].[TXM_Batch_scoring_raw_N]'))
begin
	alter table [dbo].[TXM_Batch_scoring_raw_N] add CNT_KD_CREDITCARD_SALDO int NULL;
	set @s = @s + 'CNT_KD_CREDITCARD_SALDO has been added into TXM_Batch_scoring_raw_N; ';
end;

if not exists (select * from sys.columns where [name]='CNT_KD_BUILDINGSAVINGS_SALDO' 
	and object_id = object_id('[dbo].[TXM_Batch_scoring_raw_N]'))
begin
	alter table [dbo].[TXM_Batch_scoring_raw_N] add CNT_KD_BUILDINGSAVINGS_SALDO int NULL;
	set @s = @s + 'CNT_KD_BUILDINGSAVINGS_SALDO has been added into TXM_Batch_scoring_raw_N; ';
end;

if not exists (select * from sys.columns where [name]='CNT_KD_CAPITAL_SALDO' 
	and object_id = object_id('[dbo].[TXM_Batch_scoring_raw_N]'))
begin
	alter table [dbo].[TXM_Batch_scoring_raw_N] add CNT_KD_CAPITAL_SALDO int NULL;
	set @s = @s + 'CNT_KD_CAPITAL_SALDO has been added into TXM_Batch_scoring_raw_N; ';
end;

if not exists (select * from sys.columns where [name]='CNT_KD_LIFEINSURANCE_SALDO' 
	and object_id = object_id('[dbo].[TXM_Batch_scoring_raw_N]'))
begin
	alter table [dbo].[TXM_Batch_scoring_raw_N] add CNT_KD_LIFEINSURANCE_SALDO int NULL;
	set @s = @s + 'CNT_KD_LIFEINSURANCE_SALDO has been added into TXM_Batch_scoring_raw_N; ';
end;

if not exists (select * from sys.columns where [name]='CNT_KD_NONLIFEINSURANCE_SALDO' 
	and object_id = object_id('[dbo].[TXM_Batch_scoring_raw_N]'))
begin
	alter table [dbo].[TXM_Batch_scoring_raw_N] add CNT_KD_NONLIFEINSURANCE_SALDO int NULL;
	set @s = @s + 'CNT_KD_NONLIFEINSURANCE_SALDO has been added into TXM_Batch_scoring_raw_N; ';
end;

if not exists (select * from sys.columns where [name]='AVG_KD_CURRENT_SALDO' 
	and object_id = object_id('[dbo].[TXM_Batch_scoring_raw_N]'))
begin
	alter table [dbo].[TXM_Batch_scoring_raw_N] add AVG_KD_CURRENT_SALDO numeric(15,2) NULL;
	set @s = @s + 'AVG_KD_CURRENT_SALDO has been added into TXM_Batch_scoring_raw_N; ';
end;

if not exists (select * from sys.columns where [name]='AVG_KD_SAVINGS_SALDO' 
	and object_id = object_id('[dbo].[TXM_Batch_scoring_raw_N]'))
begin
	alter table [dbo].[TXM_Batch_scoring_raw_N] add AVG_KD_SAVINGS_SALDO numeric(15,2) NULL;
	set @s = @s + 'AVG_KD_SAVINGS_SALDO has been added into TXM_Batch_scoring_raw_N; ';
end;

if not exists (select * from sys.columns where [name]='AVG_KD_LOAN_SALDO' 
	and object_id = object_id('[dbo].[TXM_Batch_scoring_raw_N]'))
begin
	alter table [dbo].[TXM_Batch_scoring_raw_N] add AVG_KD_LOAN_SALDO numeric(15,2) NULL;
	set @s = @s + 'AVG_KD_LOAN_SALDO has been added into TXM_Batch_scoring_raw_N; ';
end;

if not exists (select * from sys.columns where [name]='CNT_KD_Products' 
	and object_id = object_id('[dbo].[TXM_Batch_scoring_raw_N]'))
begin
	alter table [dbo].[TXM_Batch_scoring_raw_N] add CNT_KD_Products int NULL;
	set @s = @s + 'CNT_KD_Products has been added into TXM_Batch_scoring_raw_N; ';
end;

if not exists (select * from sys.columns where [name]='LastAccountOpenDate' 
	and object_id = object_id('[dbo].[TXM_Batch_scoring_raw_N]'))
begin
	alter table [dbo].[TXM_Batch_scoring_raw_N] add LastAccountOpenDate varchar(35) NULL;
	set @s = @s + 'LastAccountOpenDate has been added into TXM_Batch_scoring_raw_N; ';
end;

if not exists (select * from sys.columns where [name]='AccountSourceOfFunds_list' 
	and object_id = object_id('[dbo].[TXM_Batch_scoring_raw_N]'))
begin
	alter table [dbo].[TXM_Batch_scoring_raw_N] add AccountSourceOfFunds_list varchar(4000) NULL;
	set @s = @s + 'AccountSourceOfFunds_list has been added into TXM_Batch_scoring_raw_N; ';
end;

if not exists (select * from sys.columns where [name]='ProductCode_cd_list' 
	and object_id = object_id('[dbo].[TXM_Batch_scoring_raw_N]'))
begin
	alter table [dbo].[TXM_Batch_scoring_raw_N] add ProductCode_cd_list varchar(4000) NULL;
	set @s = @s + 'ProductCode_cd_list has been added into TXM_Batch_scoring_raw_N; ';
end;

if not exists (select * from sys.columns where [name]='ProductCode_list' 
	and object_id = object_id('[dbo].[TXM_Batch_scoring_raw_N]'))
begin
	alter table [dbo].[TXM_Batch_scoring_raw_N] add ProductCode_list varchar(4000) NULL;
	set @s = @s + 'ProductCode_list has been added into TXM_Batch_scoring_raw_N; ';
end;

if not exists (select * from sys.columns where [name]='AccountType_cd_list' 
	and object_id = object_id('[dbo].[TXM_Batch_scoring_raw_N]'))
begin
	alter table [dbo].[TXM_Batch_scoring_raw_N] add AccountType_cd_list varchar(4000) NULL;
	set @s = @s + 'AccountType_cd_list has been added into TXM_Batch_scoring_raw_N; ';
end;

if not exists (select * from sys.columns where [name]='AccountType_list' 
	and object_id = object_id('[dbo].[TXM_Batch_scoring_raw_N]'))
begin
	alter table [dbo].[TXM_Batch_scoring_raw_N] add AccountType_list varchar(4000) NULL;
	set @s = @s + 'AccountType_list has been added into TXM_Batch_scoring_raw_N; ';
end;

if not exists (select * from sys.columns where [name]='AccountBlockType_cd_list' 
	and object_id = object_id('[dbo].[TXM_Batch_scoring_raw_N]'))
begin
	alter table [dbo].[TXM_Batch_scoring_raw_N] add AccountBlockType_cd_list varchar(4000) NULL;
	set @s = @s + 'AccountBlockType_cd_list has been added into TXM_Batch_scoring_raw_N; ';
end;

if not exists (select * from sys.columns where [name]='AccountBlockType_list' 
	and object_id = object_id('[dbo].[TXM_Batch_scoring_raw_N]'))
begin
	alter table [dbo].[TXM_Batch_scoring_raw_N] add AccountBlockType_list varchar(4000) NULL;
	set @s = @s + 'AccountBlockType_list has been added into TXM_Batch_scoring_raw_N; ';
end;

if not exists (select * from sys.columns where [name]='MAX_KT_DURATION' 
	and object_id = object_id('[dbo].[TXM_Batch_scoring_raw_N]'))
begin
	alter table [dbo].[TXM_Batch_scoring_raw_N] add MAX_KT_DURATION int NULL;
	set @s = @s + 'MAX_KT_DURATION has been added into TXM_Batch_scoring_raw_N; ';
end;

if not exists (select * from sys.columns where [name]='AgentContact_flag' 
	and object_id = object_id('[dbo].[TXM_Batch_scoring_raw_N]'))
begin
	alter table [dbo].[TXM_Batch_scoring_raw_N] add AgentContact_flag numeric(1,0) NULL;
	set @s = @s + 'AgentContact_flag has been added into TXM_Batch_scoring_raw_N; ';
end;

if (select count(*) from sys.columns where [name]='SHORT_KT_AMOUNT' 
	and object_id = object_id('[dbo].[TXM_Batch_scoring_raw_N]') and [precision]>=20)>0
begin
	alter table [dbo].[TXM_Batch_scoring_raw_N] alter column SHORT_KT_AMOUNT numeric(15,2) NULL;
	set @s = @s + 'SHORT_KT_AMOUNT has been altered in TXM_Batch_scoring_raw_N; ';
end;

if (select count(*) from sys.columns where [name]='KD_TOTAL_SALDO' 
	and object_id = object_id('[dbo].[TXM_Batch_scoring_raw_N]') and [precision]>=20)>0
begin
	alter table [dbo].[TXM_Batch_scoring_raw_N] alter column KD_TOTAL_SALDO numeric(15,2) NULL;
	set @s = @s + 'KD_TOTAL_SALDO has been altered in TXM_Batch_scoring_raw_N; ';
end;

if (select count(*) from sys.columns where [name]='KD_BHV_THRESHOLD' 
	and object_id = object_id('[dbo].[TXM_Batch_scoring_raw_N]') and [precision]>=20)>0
begin
	alter table [dbo].[TXM_Batch_scoring_raw_N] alter column KD_BHV_THRESHOLD numeric(15,2) NULL;
	set @s = @s + 'KD_BHV_THRESHOLD has been altered in TXM_Batch_scoring_raw_N; ';
end;

if (select count(*) from sys.columns where [name]='MAX_DAY_SUM_AMOUNT_1Y' 
	and object_id = object_id('[dbo].[TXM_Batch_scoring_raw_N]') and [precision]>=20)>0
begin
	alter table [dbo].[TXM_Batch_scoring_raw_N] alter column MAX_DAY_SUM_AMOUNT_1Y numeric(15,2) NULL;
	set @s = @s + 'MAX_DAY_SUM_AMOUNT_1Y has been altered in TXM_Batch_scoring_raw_N; ';
end;

if (select count(*) from sys.columns where [name]='MAX_TRANSACTION_1Y' 
	and object_id = object_id('[dbo].[TXM_Batch_scoring_raw_N]') and [precision]>=20)>0
begin
	alter table [dbo].[TXM_Batch_scoring_raw_N] alter column MAX_TRANSACTION_1Y numeric(15,2) NULL;
	set @s = @s + 'MAX_TRANSACTION_1Y has been altered in TXM_Batch_scoring_raw_N; ';
end;

if (select count(*) from sys.columns where [name]='MAX_MONTH_SUM_AMOUNT_1Y' 
	and object_id = object_id('[dbo].[TXM_Batch_scoring_raw_N]') and [precision]>=20)>0
begin
	alter table [dbo].[TXM_Batch_scoring_raw_N] alter column MAX_MONTH_SUM_AMOUNT_1Y numeric(15,2) NULL;
	set @s = @s + 'MAX_MONTH_SUM_AMOUNT_1Y has been altered in TXM_Batch_scoring_raw_N; ';
end;

if (select count(*) from sys.columns where [name]='MAX_MONTH_SUM_INFLOW_1Y' 
	and object_id = object_id('[dbo].[TXM_Batch_scoring_raw_N]') and [precision]>=20)>0
begin
	alter table [dbo].[TXM_Batch_scoring_raw_N] alter column MAX_MONTH_SUM_INFLOW_1Y numeric(15,2) NULL;
	set @s = @s + 'MAX_MONTH_SUM_INFLOW_1Y has been altered in TXM_Batch_scoring_raw_N; ';
end;

if (select count(*) from sys.columns where [name]='MAX_MONTH_SUM_OUTFLOW_1Y' 
	and object_id = object_id('[dbo].[TXM_Batch_scoring_raw_N]') and [precision]>=20)>0
begin
	alter table [dbo].[TXM_Batch_scoring_raw_N] alter column MAX_MONTH_SUM_OUTFLOW_1Y numeric(15,2) NULL;
	set @s = @s + 'MAX_MONTH_SUM_OUTFLOW_1Y has been altered in TXM_Batch_scoring_raw_N; ';
end;

if (select count(*) from sys.columns where [name]='AVG_KD_SALDO_1Y' 
	and object_id = object_id('[dbo].[TXM_Batch_scoring_raw_N]') and [precision]>=20)>0
begin
	alter table [dbo].[TXM_Batch_scoring_raw_N] alter column AVG_KD_SALDO_1Y numeric(15,2) NULL;
	set @s = @s + 'AVG_KD_SALDO_1Y has been altered in TXM_Batch_scoring_raw_N; ';
end;

if (select count(*) from sys.columns where [name]='MAX_KD_SALDO_1Y' 
	and object_id = object_id('[dbo].[TXM_Batch_scoring_raw_N]') and [precision]>=20)>0
begin
	alter table [dbo].[TXM_Batch_scoring_raw_N] alter column MAX_KD_SALDO_1Y numeric(15,2) NULL;
	set @s = @s + 'MAX_KD_SALDO_1Y has been altered in TXM_Batch_scoring_raw_N; ';
end;

if exists (select * from sys.columns where [name]='LastAccountOpenDate' 
	and object_id = object_id('[dbo].[TXM_Batch_scoring_raw_N]') and system_type_id<>167)
begin
	alter table [dbo].[TXM_Batch_scoring_raw_N] alter column LastAccountOpenDate varchar(35) NULL;
	set @s = @s + 'LastAccountOpenDate has been altered in TXM_Batch_scoring_raw_N; ';
end;



--add new indexes
if not exists (select * from sys.indexes where [name]='TXM_Batch_scoring_raw_NC7' 
	and object_id = object_id('[dbo].[TXM_Batch_scoring_raw_N]'))
begin
	create unique clustered index TXM_Batch_scoring_raw_NC7 on [dbo].[TXM_Batch_scoring_raw_N] (txm_chunk_id,REC_ID) 
		WITH (MAXDOP = 0, ONLINE = OFF);	
	set @s = @s + 'TXM_Batch_scoring_raw_NC7-index has been created on TXM_Batch_scoring_raw_N; ';
end;

if not exists (select * from sys.indexes where [name]='TXM_Batch_scoring_raw_NI9' 
	and object_id = object_id('[dbo].[TXM_Batch_scoring_raw_N]'))
begin
	create index TXM_Batch_scoring_raw_NI9 on [dbo].[TXM_Batch_scoring_raw_N] (Customer_id) 
		include(class_5F03C6ED22324CE3AD84DEC601D19223) WITH (MAXDOP = 0, ONLINE = OFF);	
	set @s = @s + 'TXM_Batch_scoring_raw_NI8-index has been created on TXM_Batch_scoring_raw_N; ';
end;

if len(@s) = 0
	set @s = 'TXM_Batch_scoring_raw_N is ok';
print @s;
go