Search the Blog

Wednesday, August 24, 2022

DATA Migration Script For all database from EXCEL or CSV

Steps 

1- Get the Complete dump of targeted table in Excel format.

2- Insert the columns in a Table
3- Map the columns of new table and old table

4- insert the mapping columns with $ separated in table- CBA_TABLES_TANG

insert into [DATA_SECURITY].[dbo].[CBA_TABLES_TANG] (id ,[TABLE_NAME] ,[CBA_TABLE_NAME] ,[COL_01] ,[COL_02] ,[COL_03] ,[COL_04] ,[COL_05] ,[COL_06] ,[COL_07] ,[COL_08] ,[COL_09] ,[COL_10] ,[COL_11] ,[COL_12] ,[COL_13] ,[COL_14] ,[COL_15] ,[COL_16] ,[COL_17] ,[COL_18] ,[COL_19] ,[COL_20] ,[COL_21] ,[COL_22] ,[COL_23] ,[COL_24] ,[COL_25] ,[COL_26] ,[COL_27] ,[COL_28] ,[COL_29] ,[COL_30] ,[COL_31] ,[COL_32] ,[COL_33] ,[COL_34] ,[COL_35] ,[COL_36] ,[COL_37] ,[COL_38] ,[COL_39] ,[COL_40] ,[COL_41] ,[COL_42] ,[COL_43] ,[COL_44] ,[COL_45] ,[COL_46] ,[COL_47] ,[COL_48] ,[COL_49] ,[COL_50] ,[COL_51] ,[COL_52] ,[COL_53] ,[COL_54] ,[COL_55]) values( 2 ,'PRODUCT_SETUP_MASTER' ,'pgim_product' ,replace('PSM_ID$PROD_SYS_ID ',char(9),'') ,replace('PRODUCT_CODE$PROD_CODE ',char(9),'') ,replace('PRODUCT_NAME$PROD_DESC ',char(9),'') ,replace('BI_LINGUAL_DESC$PROD_DESC_BL ',char(9),'') ,replace('SHORT_DESC$PROD_SHORT_DESC ',char(9),'') ,replace('BI_LINGUAL_SHORT$PROD_SHORT_DESC_BL ',char(9),'') ,replace('CLASS_CODE$PROD_CLASS_CODE ',char(9),'') ,replace('IS_INSTALLMENT_ALLOWED$PROD_INST_YN ',char(9),'') ,replace('IS_TARIFF_APPLICABLE$PROD_TARIFF_APPL_YN ',char(9),'') ,replace('MONTHS_PRIOR_TO_POLICY_EXPIRY$PROD_CLM_EXP_YRS ',char(9),'') ,replace('CLAIM_INITIMATION_DAYS$PROD_CLM_INTM_DAYS ',char(9),'') ,replace('MAX_DISCOUNT_PER$PROD_MAX_DISC_PERC ',char(9),'') ,replace('MIN_LONG_TERM_PERIOD$PROD_MIN_LONG_PERIOD_YRS ',char(9),'') ,replace('EFFECTIVE_FROM_DT$PROD_EFF_FM_DT ',char(9),'') ,replace('EFFECTIVE_TO_DT$PROD_EFF_TO_DT ',char(9),'') ,replace('CREATED_ON$PROD_CR_DT ',char(9),'') ,replace('CREATED_BY$PROD_CR_UID ',char(9),'') ,replace('IS_SI_VALIDATION_REQ$PROD_CLM_SI_VALID_YN ',char(9),'') ,replace('IS_LOSS_DATE_VALIDATION$PROD_CLM_LOSSDT_VALID_YN ',char(9),'') ,replace('IS_REINSTATEMENT_VALIDATION_REQ$PROD_CLM_REINST_VAL_YN ',char(9),'') ,replace('RENEWAL_LONG_TERM_TYPE$PROD_REN_LTERM_TYPE ',char(9),'') ,replace('UPDATED_ON$PROD_UPD_DT ',char(9),'') ,replace('UPDATED_BY$PROD_UPD_UID ',char(9),'') ,replace('IS_ANNUAL_PROD$PROD_ANNUAL_YN ',char(9),'') ,replace('DURATION_FOR_SURVEY_REPORT$PROD_CLM_SURV_DAYS ',char(9),'') ,replace('CLAIM_RATIO_YEARS$PROD_CLM_ALLOC_BASIS ',char(9),'') ,replace('IS_CHECK_MANDATORY_COLS_FOR_FIELDS$PROD_SGN_ALL_FIELDS_YN ',char(9),'') ,replace('MINIMUM_PREMIUM$PROD_MIN_PREM_LC_1 ',char(9),'') ,replace('CLAIM_CLOSE_PROXIMATE_DAYS$PROD_CLM_CLOSE_PROX_DAYS ',char(9),'') ,replace('IS_COVER_BREAKUP_VALIDATION_REQ$PROD_CVR_BRKUP_VALID_YN ',char(9),'') ,replace('RI_TRATEY_BASIS$PROD_RI_TTY_BASIS ',char(9),'') ,replace('ENDT_RI_TREATY_BASIS$PROD_RI_END_ALLOC_BASIS ',char(9),'') ,replace('CEDING_BASIS$PROD_RI_CEDING_BASIS ',char(9),'') ,replace('IS_EXTN_ALLOWED_FOR_SHORT_PERIOD_POLICY$PROD_SH_PRD_POL_ALLOW_EXTN_YN ',char(9),'') ,replace('REFUND_TYPE$PROD_END_FM_DT_REFUND_TYPE ',char(9),'') ,replace('RATE_TYPE$PROD_RATE_IND ',char(9),'') ,replace('IS_LAPASALION_PROCESS_APPLICABLE$PROD_LAPSE_PROCESS_YN ',char(9),'') ,replace('IS_LINK_POLICY_APPLICABLE$PROD_LINK_POL_APPL_YN ',char(9),'') ,replace('IS_ADVICE_DATE_APPLICABLE$PROD_ADV_DT_YN ',char(9),'') ,replace('IS_DATE_ENTRY_ALLOWED_FOR_ADVICE_DATE$PROD_ADV_DT_ENT_YN ',char(9),'') ,replace('IS_RESTRICT_COVERS_IN_OPEN_CERTIFICATE_YN$PROD_CVR_REST_YN ',char(9),'') ,replace('IS_COMBINE_LINK_ALLOC$PROD_LINK_ALLOC_COMB_YN ',char(9),'') ,replace('PROD_DUR_TYPE$PROD_DURATION_TYPE ',char(9),'') ,replace('ACCOUNT_TYPE$PROD_ACNT_TYPE ',char(9),'') ,replace('IS_PREM_CHATGE_CHECK_REQ$PROD_PREM_CHG_CHK_YN ',char(9),'') ,replace('IS_RETROACTIVE_DATE_VALIDATION_REQ$PROD_RA_APPL_YN ',char(9),'') ,replace('IS_TERRIOSM_APPLICABLE$PROD_TERRORISM_APPL_YN ',char(9),'') ,replace('TERROISM_FOR_ALL_RISK$PROD_TERR_VAL_TYPE ',char(9),'') ,replace('REN_IDENT_PROC_DAY$PROD_REN_IDEN_DAY ',char(9),'') ,replace('AUTO_REN_PROC_DAY$PROD_AUTO_REN_PROC_DAY ',char(9),'') ,replace('IS_RENEWAL_NOTICE_DAY$PROD_NON_REN_NOTICE_DAY ',char(9),'') ,replace('INWARD_COMMISSION$PROD_RI_DED_INW_COMM ',char(9),'') ,replace('RI_PRE_TYPE$PROD_RI_PREM_TYPE ',char(9),'') ,replace('IS_IBNR_PROCESS_APPLICABLE_YN$PROD_IBNR_REQ_YN ',char(9),'') ,replace('IS_FIRST_LOSS_APPLICABLE_YN$PROD_FIRST_LOSS_APPL_YN ',char(9),'')) 5- Run the mapping script then the data will be auto populate.


declare @targested_table_name nvarchar(500);

declare @table_id int;

declare @new_table_name nvarchar(500)

declare @nunmber_rows_in_excel int

set @targested_table_name='pgim_product'

set @new_table_name='[PRODUCT_SETUP].[PRODUCT_SETUP_MASTER]'

set @table_id=2

SELECT @nunmber_rows_in_excel=

  ( (CASE WHEN col_01 IS NULL THEN 0 ELSE 1 END)

  + (CASE WHEN col_02 IS NULL THEN 0 ELSE 1 END)

  + (CASE WHEN col_03 IS NULL THEN 0 ELSE 1 END)

  + (CASE WHEN col_04 IS NULL THEN 0 ELSE 1 END)

  + (CASE WHEN col_05 IS NULL THEN 0 ELSE 1 END)

  + (CASE WHEN col_06 IS NULL THEN 0 ELSE 1 END)

  + (CASE WHEN col_07 IS NULL THEN 0 ELSE 1 END)

  + (CASE WHEN col_08 IS NULL THEN 0 ELSE 1 END)

  + (CASE WHEN col_09 IS NULL THEN 0 ELSE 1 END)

  + (CASE WHEN col_10 IS NULL THEN 0 ELSE 1 END)

  + (CASE WHEN col_11 IS NULL THEN 0 ELSE 1 END)

  + (CASE WHEN col_12 IS NULL THEN 0 ELSE 1 END)

  + (CASE WHEN col_13 IS NULL THEN 0 ELSE 1 END)

  + (CASE WHEN col_14 IS NULL THEN 0 ELSE 1 END)

  + (CASE WHEN col_15 IS NULL THEN 0 ELSE 1 END)

  + (CASE WHEN col_16 IS NULL THEN 0 ELSE 1 END)

  + (CASE WHEN col_17 IS NULL THEN 0 ELSE 1 END)

  + (CASE WHEN col_18 IS NULL THEN 0 ELSE 1 END)

  + (CASE WHEN col_19 IS NULL THEN 0 ELSE 1 END)

  + (CASE WHEN col_20 IS NULL THEN 0 ELSE 1 END)

  + (CASE WHEN col_21 IS NULL THEN 0 ELSE 1 END)

  + (CASE WHEN col_22 IS NULL THEN 0 ELSE 1 END)

  + (CASE WHEN col_23 IS NULL THEN 0 ELSE 1 END)

  + (CASE WHEN col_24 IS NULL THEN 0 ELSE 1 END)

  + (CASE WHEN col_25 IS NULL THEN 0 ELSE 1 END)

  + (CASE WHEN col_26 IS NULL THEN 0 ELSE 1 END)

  + (CASE WHEN col_27 IS NULL THEN 0 ELSE 1 END)

  + (CASE WHEN col_28 IS NULL THEN 0 ELSE 1 END)

  + (CASE WHEN col_29 IS NULL THEN 0 ELSE 1 END)

  + (CASE WHEN col_30 IS NULL THEN 0 ELSE 1 END)

  + (CASE WHEN col_31 IS NULL THEN 0 ELSE 1 END)

  + (CASE WHEN col_32 IS NULL THEN 0 ELSE 1 END)

  + (CASE WHEN col_33 IS NULL THEN 0 ELSE 1 END)

  + (CASE WHEN col_34 IS NULL THEN 0 ELSE 1 END)

  + (CASE WHEN col_35 IS NULL THEN 0 ELSE 1 END)

  + (CASE WHEN col_36 IS NULL THEN 0 ELSE 1 END)

  + (CASE WHEN col_37 IS NULL THEN 0 ELSE 1 END)

  + (CASE WHEN col_38 IS NULL THEN 0 ELSE 1 END)

  + (CASE WHEN col_39 IS NULL THEN 0 ELSE 1 END)

  + (CASE WHEN col_40 IS NULL THEN 0 ELSE 1 END)

  + (CASE WHEN col_41 IS NULL THEN 0 ELSE 1 END)

  + (CASE WHEN col_42 IS NULL THEN 0 ELSE 1 END)

  + (CASE WHEN col_43 IS NULL THEN 0 ELSE 1 END)

  + (CASE WHEN col_44 IS NULL THEN 0 ELSE 1 END)

  + (CASE WHEN col_45 IS NULL THEN 0 ELSE 1 END)

  + (CASE WHEN col_46 IS NULL THEN 0 ELSE 1 END)

  + (CASE WHEN col_47 IS NULL THEN 0 ELSE 1 END)

  + (CASE WHEN col_48 IS NULL THEN 0 ELSE 1 END)

  + (CASE WHEN col_49 IS NULL THEN 0 ELSE 1 END)

  + (CASE WHEN col_50 IS NULL THEN 0 ELSE 1 END)

  + (CASE WHEN col_51 IS NULL THEN 0 ELSE 1 END)

  + (CASE WHEN col_52 IS NULL THEN 0 ELSE 1 END)

  + (CASE WHEN col_53 IS NULL THEN 0 ELSE 1 END)

  + (CASE WHEN col_54 IS NULL THEN 0 ELSE 1 END)

  + (CASE WHEN col_55 IS NULL THEN 0 ELSE 1 END)

  + (CASE WHEN col_56 IS NULL THEN 0 ELSE 1 END)

  + (CASE WHEN col_57 IS NULL THEN 0 ELSE 1 END)

  + (CASE WHEN col_58 IS NULL THEN 0 ELSE 1 END)

  + (CASE WHEN col_59 IS NULL THEN 0 ELSE 1 END)

  + (CASE WHEN col_60 IS NULL THEN 0 ELSE 1 END)

  + (CASE WHEN col_61 IS NULL THEN 0 ELSE 1 END)

  + (CASE WHEN col_62 IS NULL THEN 0 ELSE 1 END)

  + (CASE WHEN col_63 IS NULL THEN 0 ELSE 1 END)

  + (CASE WHEN col_64 IS NULL THEN 0 ELSE 1 END)

  + (CASE WHEN col_65 IS NULL THEN 0 ELSE 1 END)

  + (CASE WHEN col_66 IS NULL THEN 0 ELSE 1 END)

  + (CASE WHEN col_67 IS NULL THEN 0 ELSE 1 END)

  + (CASE WHEN col_68 IS NULL THEN 0 ELSE 1 END)

  + (CASE WHEN col_69 IS NULL THEN 0 ELSE 1 END)

  + (CASE WHEN col_70 IS NULL THEN 0 ELSE 1 END)

  + (CASE WHEN col_71 IS NULL THEN 0 ELSE 1 END)

  + (CASE WHEN col_72 IS NULL THEN 0 ELSE 1 END)

  + (CASE WHEN col_73 IS NULL THEN 0 ELSE 1 END)

  + (CASE WHEN col_74 IS NULL THEN 0 ELSE 1 END)

  + (CASE WHEN col_75 IS NULL THEN 0 ELSE 1 END)

  + (CASE WHEN col_76 IS NULL THEN 0 ELSE 1 END)

  + (CASE WHEN col_77 IS NULL THEN 0 ELSE 1 END)

  + (CASE WHEN col_78 IS NULL THEN 0 ELSE 1 END)

  + (CASE WHEN col_79 IS NULL THEN 0 ELSE 1 END)

  + (CASE WHEN col_80 IS NULL THEN 0 ELSE 1 END)

  + (CASE WHEN col_81 IS NULL THEN 0 ELSE 1 END)

  + (CASE WHEN col_82 IS NULL THEN 0 ELSE 1 END)

  + (CASE WHEN col_83 IS NULL THEN 0 ELSE 1 END)

  + (CASE WHEN col_84 IS NULL THEN 0 ELSE 1 END)

  + (CASE WHEN col_85 IS NULL THEN 0 ELSE 1 END)

  + (CASE WHEN col_86 IS NULL THEN 0 ELSE 1 END)

  + (CASE WHEN col_87 IS NULL THEN 0 ELSE 1 END)

  + (CASE WHEN col_88 IS NULL THEN 0 ELSE 1 END)

  + (CASE WHEN col_89 IS NULL THEN 0 ELSE 1 END)

  + (CASE WHEN col_90 IS NULL THEN 0 ELSE 1 END)

  + (CASE WHEN col_91 IS NULL THEN 0 ELSE 1 END)

  + (CASE WHEN col_92 IS NULL THEN 0 ELSE 1 END)

  + (CASE WHEN col_93 IS NULL THEN 0 ELSE 1 END)

  + (CASE WHEN col_94 IS NULL THEN 0 ELSE 1 END)

  + (CASE WHEN col_95 IS NULL THEN 0 ELSE 1 END)

  + (CASE WHEN col_96 IS NULL THEN 0 ELSE 1 END)

  + (CASE WHEN col_97 IS NULL THEN 0 ELSE 1 END)

  + (CASE WHEN col_98 IS NULL THEN 0 ELSE 1 END)

  + (CASE WHEN col_99 IS NULL THEN 0 ELSE 1 END)

 ) 

FROM [DATA_SECURITY].[dbo].[CBA_TABLES]

WHERE TABLE_NAME=@targested_table_name



create table #Excel_data

(COL_01 Nvarchar(100))

 declare @column_creator int;

 set @column_creator=2

 declare @new_column_name nvarchar(50);

 while(@column_creator<=@nunmber_rows_in_excel)

 begin


set @new_column_name=case when @column_creator<10 then 'COL_0'+convert(nvarchar,@column_creator) else 'COL_'+convert(nvarchar,@column_creator)  end

declare @DynamicSQL nvarchar(max)

SET @DynamicSQL = 'ALTER TABLE #Excel_data ADD ['+ @new_column_name +'] NVARCHAR(1000)'

EXEC(@DynamicSQL)

 set @column_creator=@column_creator+1

 end


BULK INSERT #Excel_data 

FROM 'C:\Users\sawan\Desktop\CBA_MIG\CBA_MIG.csv'

WITH

(   FIRSTROW = 2,

    FIELDTERMINATOR = ',',

    ROWTERMINATOR = '\n', 

    TABLOCK

)

declare @new_table_colum_list nvarchar(max)

declare @old_table_colum_list nvarchar(max)


declare @New_colum_count int

select  @new_table_colum_list=

  ( (CASE WHEN col_01 IS NULL THEN '' ELSE concat(LEFT(col_01, CHARINDEX('$', col_01) -1),',')     END)

  + (CASE WHEN col_02 IS NULL THEN '' ELSE concat(LEFT(col_02, CHARINDEX('$', col_02) -1),',')     END)

  + (CASE WHEN col_03 IS NULL THEN '' ELSE concat(LEFT(col_03, CHARINDEX('$', col_03) -1),',')     END)

  + (CASE WHEN col_04 IS NULL THEN '' ELSE concat(LEFT(col_04, CHARINDEX('$', col_04) -1),',')     END)

  + (CASE WHEN col_05 IS NULL THEN '' ELSE concat(LEFT(col_05, CHARINDEX('$', col_05) -1),',')     END)

  + (CASE WHEN col_06 IS NULL THEN '' ELSE concat(LEFT(col_06, CHARINDEX('$', col_06) -1),',')     END)

  + (CASE WHEN col_07 IS NULL THEN '' ELSE concat(LEFT(col_07, CHARINDEX('$', col_07) -1),',')     END)

  + (CASE WHEN col_08 IS NULL THEN '' ELSE concat(LEFT(col_08, CHARINDEX('$', col_08) -1),',')     END)

  + (CASE WHEN col_09 IS NULL THEN '' ELSE concat(LEFT(col_09, CHARINDEX('$', col_09) -1),',')     END)

  + (CASE WHEN col_10 IS NULL THEN '' ELSE concat(LEFT(col_10, CHARINDEX('$', col_10) -1),',')     END)

  + (CASE WHEN col_11 IS NULL THEN '' ELSE concat(LEFT(col_11, CHARINDEX('$', col_11) -1),',')     END)

  + (CASE WHEN col_12 IS NULL THEN '' ELSE concat(LEFT(col_12, CHARINDEX('$', col_12) -1),',')     END)

  + (CASE WHEN col_13 IS NULL THEN '' ELSE concat(LEFT(col_13, CHARINDEX('$', col_13) -1),',')     END)

  + (CASE WHEN col_14 IS NULL THEN '' ELSE concat(LEFT(col_14, CHARINDEX('$', col_14) -1),',')     END)

  + (CASE WHEN col_15 IS NULL THEN '' ELSE concat(LEFT(col_15, CHARINDEX('$', col_15) -1),',')     END)

  + (CASE WHEN col_16 IS NULL THEN '' ELSE concat(LEFT(col_16, CHARINDEX('$', col_16) -1),',')     END)

  + (CASE WHEN col_17 IS NULL THEN '' ELSE concat(LEFT(col_17, CHARINDEX('$', col_17) -1),',')     END)

  + (CASE WHEN col_18 IS NULL THEN '' ELSE concat(LEFT(col_18, CHARINDEX('$', col_18) -1),',')     END)

  + (CASE WHEN col_19 IS NULL THEN '' ELSE concat(LEFT(col_19, CHARINDEX('$', col_19) -1),',')     END)

  + (CASE WHEN col_20 IS NULL THEN '' ELSE concat(LEFT(col_20, CHARINDEX('$', col_20) -1),',')     END)

  + (CASE WHEN col_21 IS NULL THEN '' ELSE concat(LEFT(col_21, CHARINDEX('$', col_21) -1),',')     END)

  + (CASE WHEN col_22 IS NULL THEN '' ELSE concat(LEFT(col_22, CHARINDEX('$', col_22) -1),',')     END)

  + (CASE WHEN col_23 IS NULL THEN '' ELSE concat(LEFT(col_23, CHARINDEX('$', col_23) -1),',')     END)

  + (CASE WHEN col_24 IS NULL THEN '' ELSE concat(LEFT(col_24, CHARINDEX('$', col_24) -1),',')     END)

  + (CASE WHEN col_25 IS NULL THEN '' ELSE concat(LEFT(col_25, CHARINDEX('$', col_25) -1),',')     END)

  + (CASE WHEN col_26 IS NULL THEN '' ELSE concat(LEFT(col_26, CHARINDEX('$', col_26) -1),',')     END)

  + (CASE WHEN col_27 IS NULL THEN '' ELSE concat(LEFT(col_27, CHARINDEX('$', col_27) -1),',')     END)

  + (CASE WHEN col_28 IS NULL THEN '' ELSE concat(LEFT(col_28, CHARINDEX('$', col_28) -1),',')     END)

  + (CASE WHEN col_29 IS NULL THEN '' ELSE concat(LEFT(col_29, CHARINDEX('$', col_29) -1),',')     END)

  + (CASE WHEN col_30 IS NULL THEN '' ELSE concat(LEFT(col_30, CHARINDEX('$', col_30) -1),',')     END)

  + (CASE WHEN col_31 IS NULL THEN '' ELSE concat(LEFT(col_31, CHARINDEX('$', col_31) -1),',')     END)

  + (CASE WHEN col_32 IS NULL THEN '' ELSE concat(LEFT(col_32, CHARINDEX('$', col_32) -1),',')     END)

  + (CASE WHEN col_33 IS NULL THEN '' ELSE concat(LEFT(col_33, CHARINDEX('$', col_33) -1),',')     END)

  + (CASE WHEN col_34 IS NULL THEN '' ELSE concat(LEFT(col_34, CHARINDEX('$', col_34) -1),',')     END)

  + (CASE WHEN col_35 IS NULL THEN '' ELSE concat(LEFT(col_35, CHARINDEX('$', col_35) -1),',')     END)

  + (CASE WHEN col_36 IS NULL THEN '' ELSE concat(LEFT(col_36, CHARINDEX('$', col_36) -1),',')     END)

  + (CASE WHEN col_37 IS NULL THEN '' ELSE concat(LEFT(col_37, CHARINDEX('$', col_37) -1),',')     END)

  + (CASE WHEN col_38 IS NULL THEN '' ELSE concat(LEFT(col_38, CHARINDEX('$', col_38) -1),',')     END)

  + (CASE WHEN col_39 IS NULL THEN '' ELSE concat(LEFT(col_39, CHARINDEX('$', col_39) -1),',')     END)

  + (CASE WHEN col_40 IS NULL THEN '' ELSE concat(LEFT(col_40, CHARINDEX('$', col_40) -1),',')     END)

  + (CASE WHEN col_41 IS NULL THEN '' ELSE concat(LEFT(col_41, CHARINDEX('$', col_41) -1),',')     END)

  + (CASE WHEN col_42 IS NULL THEN '' ELSE concat(LEFT(col_42, CHARINDEX('$', col_42) -1),',')     END)

  + (CASE WHEN col_43 IS NULL THEN '' ELSE concat(LEFT(col_43, CHARINDEX('$', col_43) -1),',')     END)

  + (CASE WHEN col_44 IS NULL THEN '' ELSE concat(LEFT(col_44, CHARINDEX('$', col_44) -1),',')     END)

  + (CASE WHEN col_45 IS NULL THEN '' ELSE concat(LEFT(col_45, CHARINDEX('$', col_45) -1),',')     END)

  + (CASE WHEN col_46 IS NULL THEN '' ELSE concat(LEFT(col_46, CHARINDEX('$', col_46) -1),',')     END)

  + (CASE WHEN col_47 IS NULL THEN '' ELSE concat(LEFT(col_47, CHARINDEX('$', col_47) -1),',')     END)

  + (CASE WHEN col_48 IS NULL THEN '' ELSE concat(LEFT(col_48, CHARINDEX('$', col_48) -1),',')     END)

  + (CASE WHEN col_49 IS NULL THEN '' ELSE concat(LEFT(col_49, CHARINDEX('$', col_49) -1),',')     END)

  + (CASE WHEN col_50 IS NULL THEN '' ELSE concat(LEFT(col_50, CHARINDEX('$', col_50) -1),',')     END)

  + (CASE WHEN col_51 IS NULL THEN '' ELSE concat(LEFT(col_51, CHARINDEX('$', col_51) -1),',')     END)

  + (CASE WHEN col_52 IS NULL THEN '' ELSE concat(LEFT(col_52, CHARINDEX('$', col_52) -1),',')     END)

  + (CASE WHEN col_53 IS NULL THEN '' ELSE concat(LEFT(col_53, CHARINDEX('$', col_53) -1),',')     END)

  + (CASE WHEN col_54 IS NULL THEN '' ELSE concat(LEFT(col_54, CHARINDEX('$', col_54) -1),',')     END)

  + (CASE WHEN col_55 IS NULL THEN '' ELSE concat(LEFT(col_55, CHARINDEX('$', col_55) -1),',')     END)

  + (CASE WHEN col_56 IS NULL THEN '' ELSE concat(LEFT(col_56, CHARINDEX('$', col_56) -1),',')     END)

  + (CASE WHEN col_57 IS NULL THEN '' ELSE concat(LEFT(col_57, CHARINDEX('$', col_57) -1),',')     END)

  + (CASE WHEN col_58 IS NULL THEN '' ELSE concat(LEFT(col_58, CHARINDEX('$', col_58) -1),',')     END)

  + (CASE WHEN col_59 IS NULL THEN '' ELSE concat(LEFT(col_59, CHARINDEX('$', col_59) -1),',')     END)

  + (CASE WHEN col_60 IS NULL THEN '' ELSE concat(LEFT(col_60, CHARINDEX('$', col_60) -1),',')     END)

  + (CASE WHEN col_61 IS NULL THEN '' ELSE concat(LEFT(col_61, CHARINDEX('$', col_61) -1),',')     END)

  + (CASE WHEN col_62 IS NULL THEN '' ELSE concat(LEFT(col_62, CHARINDEX('$', col_62) -1),',')     END)

  + (CASE WHEN col_63 IS NULL THEN '' ELSE concat(LEFT(col_63, CHARINDEX('$', col_63) -1),',')     END)

  + (CASE WHEN col_64 IS NULL THEN '' ELSE concat(LEFT(col_64, CHARINDEX('$', col_64) -1),',')     END)

  + (CASE WHEN col_65 IS NULL THEN '' ELSE concat(LEFT(col_65, CHARINDEX('$', col_65) -1),',')     END)

  + (CASE WHEN col_66 IS NULL THEN '' ELSE concat(LEFT(col_66, CHARINDEX('$', col_66) -1),',')     END)

  + (CASE WHEN col_67 IS NULL THEN '' ELSE concat(LEFT(col_67, CHARINDEX('$', col_67) -1),',')     END)

  + (CASE WHEN col_68 IS NULL THEN '' ELSE concat(LEFT(col_68, CHARINDEX('$', col_68) -1),',')     END)

  + (CASE WHEN col_69 IS NULL THEN '' ELSE concat(LEFT(col_69, CHARINDEX('$', col_69) -1),',')     END)

  + (CASE WHEN col_70 IS NULL THEN '' ELSE concat(LEFT(col_70, CHARINDEX('$', col_70) -1),',')     END)

  + (CASE WHEN col_71 IS NULL THEN '' ELSE concat(LEFT(col_71, CHARINDEX('$', col_71) -1),',')     END)

  + (CASE WHEN col_72 IS NULL THEN '' ELSE concat(LEFT(col_72, CHARINDEX('$', col_72) -1),',')     END)

  + (CASE WHEN col_73 IS NULL THEN '' ELSE concat(LEFT(col_73, CHARINDEX('$', col_73) -1),',')     END)

  + (CASE WHEN col_74 IS NULL THEN '' ELSE concat(LEFT(col_74, CHARINDEX('$', col_74) -1),',')     END)

  + (CASE WHEN col_75 IS NULL THEN '' ELSE concat(LEFT(col_75, CHARINDEX('$', col_75) -1),',')     END)

  + (CASE WHEN col_76 IS NULL THEN '' ELSE concat(LEFT(col_76, CHARINDEX('$', col_76) -1),',')     END)

  + (CASE WHEN col_77 IS NULL THEN '' ELSE concat(LEFT(col_77, CHARINDEX('$', col_77) -1),',')     END)

  + (CASE WHEN col_78 IS NULL THEN '' ELSE concat(LEFT(col_78, CHARINDEX('$', col_78) -1),',')     END)

  + (CASE WHEN col_79 IS NULL THEN '' ELSE concat(LEFT(col_79, CHARINDEX('$', col_79) -1),',')     END)

  + (CASE WHEN col_80 IS NULL THEN '' ELSE concat(LEFT(col_80, CHARINDEX('$', col_80) -1),',')     END)

  + (CASE WHEN col_81 IS NULL THEN '' ELSE concat(LEFT(col_81, CHARINDEX('$', col_81) -1),',')     END)

  + (CASE WHEN col_82 IS NULL THEN '' ELSE concat(LEFT(col_82, CHARINDEX('$', col_82) -1),',')     END)

  + (CASE WHEN col_83 IS NULL THEN '' ELSE concat(LEFT(col_83, CHARINDEX('$', col_83) -1),',')     END)

  + (CASE WHEN col_84 IS NULL THEN '' ELSE concat(LEFT(col_84, CHARINDEX('$', col_84) -1),',')     END)

  + (CASE WHEN col_85 IS NULL THEN '' ELSE concat(LEFT(col_85, CHARINDEX('$', col_85) -1),',')     END)

  + (CASE WHEN col_86 IS NULL THEN '' ELSE concat(LEFT(col_86, CHARINDEX('$', col_86) -1),',')     END)

  + (CASE WHEN col_87 IS NULL THEN '' ELSE concat(LEFT(col_87, CHARINDEX('$', col_87) -1),',')     END)

  + (CASE WHEN col_88 IS NULL THEN '' ELSE concat(LEFT(col_88, CHARINDEX('$', col_88) -1),',')     END)

  + (CASE WHEN col_89 IS NULL THEN '' ELSE concat(LEFT(col_89, CHARINDEX('$', col_89) -1),',')     END)

  + (CASE WHEN col_90 IS NULL THEN '' ELSE concat(LEFT(col_90, CHARINDEX('$', col_90) -1),',')     END)

  + (CASE WHEN col_91 IS NULL THEN '' ELSE concat(LEFT(col_91, CHARINDEX('$', col_91) -1),',')     END)

  + (CASE WHEN col_92 IS NULL THEN '' ELSE concat(LEFT(col_92, CHARINDEX('$', col_92) -1),',')     END)

  + (CASE WHEN col_93 IS NULL THEN '' ELSE concat(LEFT(col_93, CHARINDEX('$', col_93) -1),',')     END)

  + (CASE WHEN col_94 IS NULL THEN '' ELSE concat(LEFT(col_94, CHARINDEX('$', col_94) -1),',')     END)

  + (CASE WHEN col_95 IS NULL THEN '' ELSE concat(LEFT(col_95, CHARINDEX('$', col_95) -1),',')     END)

  + (CASE WHEN col_96 IS NULL THEN '' ELSE concat(LEFT(col_96, CHARINDEX('$', col_96) -1),',')     END)

  + (CASE WHEN col_97 IS NULL THEN '' ELSE concat(LEFT(col_97, CHARINDEX('$', col_97) -1),',')     END)

  + (CASE WHEN col_98 IS NULL THEN '' ELSE concat(LEFT(col_98, CHARINDEX('$', col_98) -1),',')     END)

  + (CASE WHEN col_99 IS NULL THEN '' ELSE concat(LEFT(col_99, CHARINDEX('$', col_99) -1),',')     END)) 

from [DATA_SECURITY].[dbo].[CBA_TABLES_TANG] where id=@table_id

print(@new_table_colum_list)



select  @old_table_colum_list=

  ( (CASE WHEN COL_01 IS NULL THEN '' ELSE CONCAT(SUBSTRING(COL_01,LEN(LEFT(COL_01, CHARINDEX('$', COL_01)+ 1)),LEN(COL_01)),',')   END)

  + (CASE WHEN COL_02 IS NULL THEN '' ELSE CONCAT(SUBSTRING(COL_02,LEN(LEFT(COL_02, CHARINDEX('$', COL_02)+ 1)),LEN(COL_02)),',')   END)

  + (CASE WHEN COL_03 IS NULL THEN '' ELSE CONCAT(SUBSTRING(COL_03,LEN(LEFT(COL_03, CHARINDEX('$', COL_03)+ 1)),LEN(COL_03)),',')   END)

  + (CASE WHEN COL_04 IS NULL THEN '' ELSE CONCAT(SUBSTRING(COL_04,LEN(LEFT(COL_04, CHARINDEX('$', COL_04)+ 1)),LEN(COL_04)),',')   END)

  + (CASE WHEN COL_05 IS NULL THEN '' ELSE CONCAT(SUBSTRING(COL_05,LEN(LEFT(COL_05, CHARINDEX('$', COL_05)+ 1)),LEN(COL_05)),',')   END)

  + (CASE WHEN COL_06 IS NULL THEN '' ELSE CONCAT(SUBSTRING(COL_06,LEN(LEFT(COL_06, CHARINDEX('$', COL_06)+ 1)),LEN(COL_06)),',')   END)

  + (CASE WHEN COL_07 IS NULL THEN '' ELSE CONCAT(SUBSTRING(COL_07,LEN(LEFT(COL_07, CHARINDEX('$', COL_07)+ 1)),LEN(COL_07)),',')   END)

  + (CASE WHEN COL_08 IS NULL THEN '' ELSE CONCAT(SUBSTRING(COL_08,LEN(LEFT(COL_08, CHARINDEX('$', COL_08)+ 1)),LEN(COL_08)),',')   END)

  + (CASE WHEN COL_09 IS NULL THEN '' ELSE CONCAT(SUBSTRING(COL_09,LEN(LEFT(COL_09, CHARINDEX('$', COL_09)+ 1)),LEN(COL_09)),',')   END)

  + (CASE WHEN COL_10 IS NULL THEN '' ELSE CONCAT(SUBSTRING(COL_10,LEN(LEFT(COL_10, CHARINDEX('$', COL_10)+ 1)),LEN(COL_10)),',')   END)

  + (CASE WHEN COL_11 IS NULL THEN '' ELSE CONCAT(SUBSTRING(COL_11,LEN(LEFT(COL_11, CHARINDEX('$', COL_11)+ 1)),LEN(COL_11)),',')   END)

  + (CASE WHEN COL_12 IS NULL THEN '' ELSE CONCAT(SUBSTRING(COL_12,LEN(LEFT(COL_12, CHARINDEX('$', COL_12)+ 1)),LEN(COL_12)),',')   END)

  + (CASE WHEN COL_13 IS NULL THEN '' ELSE CONCAT(SUBSTRING(COL_13,LEN(LEFT(COL_13, CHARINDEX('$', COL_13)+ 1)),LEN(COL_13)),',')   END)

  + (CASE WHEN COL_14 IS NULL THEN '' ELSE CONCAT(SUBSTRING(COL_14,LEN(LEFT(COL_14, CHARINDEX('$', COL_14)+ 1)),LEN(COL_14)),',')   END)

  + (CASE WHEN COL_15 IS NULL THEN '' ELSE CONCAT(SUBSTRING(COL_15,LEN(LEFT(COL_15, CHARINDEX('$', COL_15)+ 1)),LEN(COL_15)),',')   END)

  + (CASE WHEN COL_16 IS NULL THEN '' ELSE CONCAT(SUBSTRING(COL_16,LEN(LEFT(COL_16, CHARINDEX('$', COL_16)+ 1)),LEN(COL_16)),',')   END)

  + (CASE WHEN COL_17 IS NULL THEN '' ELSE CONCAT(SUBSTRING(COL_17,LEN(LEFT(COL_17, CHARINDEX('$', COL_17)+ 1)),LEN(COL_17)),',')   END)

  + (CASE WHEN COL_18 IS NULL THEN '' ELSE CONCAT(SUBSTRING(COL_18,LEN(LEFT(COL_18, CHARINDEX('$', COL_18)+ 1)),LEN(COL_18)),',')   END)

  + (CASE WHEN COL_19 IS NULL THEN '' ELSE CONCAT(SUBSTRING(COL_19,LEN(LEFT(COL_19, CHARINDEX('$', COL_19)+ 1)),LEN(COL_19)),',')   END)

  + (CASE WHEN COL_20 IS NULL THEN '' ELSE CONCAT(SUBSTRING(COL_20,LEN(LEFT(COL_20, CHARINDEX('$', COL_20)+ 1)),LEN(COL_20)),',')   END)

  + (CASE WHEN COL_21 IS NULL THEN '' ELSE CONCAT(SUBSTRING(COL_21,LEN(LEFT(COL_21, CHARINDEX('$', COL_21)+ 1)),LEN(COL_21)),',')   END)

  + (CASE WHEN COL_22 IS NULL THEN '' ELSE CONCAT(SUBSTRING(COL_22,LEN(LEFT(COL_22, CHARINDEX('$', COL_22)+ 1)),LEN(COL_22)),',')   END)

  + (CASE WHEN COL_23 IS NULL THEN '' ELSE CONCAT(SUBSTRING(COL_23,LEN(LEFT(COL_23, CHARINDEX('$', COL_23)+ 1)),LEN(COL_23)),',')   END)

  + (CASE WHEN COL_24 IS NULL THEN '' ELSE CONCAT(SUBSTRING(COL_24,LEN(LEFT(COL_24, CHARINDEX('$', COL_24)+ 1)),LEN(COL_24)),',')   END)

  + (CASE WHEN COL_25 IS NULL THEN '' ELSE CONCAT(SUBSTRING(COL_25,LEN(LEFT(COL_25, CHARINDEX('$', COL_25)+ 1)),LEN(COL_25)),',')   END)

  + (CASE WHEN COL_26 IS NULL THEN '' ELSE CONCAT(SUBSTRING(COL_26,LEN(LEFT(COL_26, CHARINDEX('$', COL_26)+ 1)),LEN(COL_26)),',')   END)

  + (CASE WHEN COL_27 IS NULL THEN '' ELSE CONCAT(SUBSTRING(COL_27,LEN(LEFT(COL_27, CHARINDEX('$', COL_27)+ 1)),LEN(COL_27)),',')   END)

  + (CASE WHEN COL_28 IS NULL THEN '' ELSE CONCAT(SUBSTRING(COL_28,LEN(LEFT(COL_28, CHARINDEX('$', COL_28)+ 1)),LEN(COL_28)),',')   END)

  + (CASE WHEN COL_29 IS NULL THEN '' ELSE CONCAT(SUBSTRING(COL_29,LEN(LEFT(COL_29, CHARINDEX('$', COL_29)+ 1)),LEN(COL_29)),',')   END)

  + (CASE WHEN COL_30 IS NULL THEN '' ELSE CONCAT(SUBSTRING(COL_30,LEN(LEFT(COL_30, CHARINDEX('$', COL_30)+ 1)),LEN(COL_30)),',')   END)

  + (CASE WHEN COL_31 IS NULL THEN '' ELSE CONCAT(SUBSTRING(COL_31,LEN(LEFT(COL_31, CHARINDEX('$', COL_31)+ 1)),LEN(COL_31)),',')   END)

  + (CASE WHEN COL_32 IS NULL THEN '' ELSE CONCAT(SUBSTRING(COL_32,LEN(LEFT(COL_32, CHARINDEX('$', COL_32)+ 1)),LEN(COL_32)),',')   END)

  + (CASE WHEN COL_33 IS NULL THEN '' ELSE CONCAT(SUBSTRING(COL_33,LEN(LEFT(COL_33, CHARINDEX('$', COL_33)+ 1)),LEN(COL_33)),',')   END)

  + (CASE WHEN COL_34 IS NULL THEN '' ELSE CONCAT(SUBSTRING(COL_34,LEN(LEFT(COL_34, CHARINDEX('$', COL_34)+ 1)),LEN(COL_34)),',')   END)

  + (CASE WHEN COL_35 IS NULL THEN '' ELSE CONCAT(SUBSTRING(COL_35,LEN(LEFT(COL_35, CHARINDEX('$', COL_35)+ 1)),LEN(COL_35)),',')   END)

  + (CASE WHEN COL_36 IS NULL THEN '' ELSE CONCAT(SUBSTRING(COL_36,LEN(LEFT(COL_36, CHARINDEX('$', COL_36)+ 1)),LEN(COL_36)),',')   END)

  + (CASE WHEN COL_37 IS NULL THEN '' ELSE CONCAT(SUBSTRING(COL_37,LEN(LEFT(COL_37, CHARINDEX('$', COL_37)+ 1)),LEN(COL_37)),',')   END)

  + (CASE WHEN COL_38 IS NULL THEN '' ELSE CONCAT(SUBSTRING(COL_38,LEN(LEFT(COL_38, CHARINDEX('$', COL_38)+ 1)),LEN(COL_38)),',')   END)

  + (CASE WHEN COL_39 IS NULL THEN '' ELSE CONCAT(SUBSTRING(COL_39,LEN(LEFT(COL_39, CHARINDEX('$', COL_39)+ 1)),LEN(COL_39)),',')   END)

  + (CASE WHEN COL_40 IS NULL THEN '' ELSE CONCAT(SUBSTRING(COL_40,LEN(LEFT(COL_40, CHARINDEX('$', COL_40)+ 1)),LEN(COL_40)),',')   END)

  + (CASE WHEN COL_41 IS NULL THEN '' ELSE CONCAT(SUBSTRING(COL_41,LEN(LEFT(COL_41, CHARINDEX('$', COL_41)+ 1)),LEN(COL_41)),',')   END)

  + (CASE WHEN COL_42 IS NULL THEN '' ELSE CONCAT(SUBSTRING(COL_42,LEN(LEFT(COL_42, CHARINDEX('$', COL_42)+ 1)),LEN(COL_42)),',')   END)

  + (CASE WHEN COL_43 IS NULL THEN '' ELSE CONCAT(SUBSTRING(COL_43,LEN(LEFT(COL_43, CHARINDEX('$', COL_43)+ 1)),LEN(COL_43)),',')   END)

  + (CASE WHEN COL_44 IS NULL THEN '' ELSE CONCAT(SUBSTRING(COL_44,LEN(LEFT(COL_44, CHARINDEX('$', COL_44)+ 1)),LEN(COL_44)),',')   END)

  + (CASE WHEN COL_45 IS NULL THEN '' ELSE CONCAT(SUBSTRING(COL_45,LEN(LEFT(COL_45, CHARINDEX('$', COL_45)+ 1)),LEN(COL_45)),',')   END)

  + (CASE WHEN COL_46 IS NULL THEN '' ELSE CONCAT(SUBSTRING(COL_46,LEN(LEFT(COL_46, CHARINDEX('$', COL_46)+ 1)),LEN(COL_46)),',')   END)

  + (CASE WHEN COL_47 IS NULL THEN '' ELSE CONCAT(SUBSTRING(COL_47,LEN(LEFT(COL_47, CHARINDEX('$', COL_47)+ 1)),LEN(COL_47)),',')   END)

  + (CASE WHEN COL_48 IS NULL THEN '' ELSE CONCAT(SUBSTRING(COL_48,LEN(LEFT(COL_48, CHARINDEX('$', COL_48)+ 1)),LEN(COL_48)),',')   END)

  + (CASE WHEN COL_49 IS NULL THEN '' ELSE CONCAT(SUBSTRING(COL_49,LEN(LEFT(COL_49, CHARINDEX('$', COL_49)+ 1)),LEN(COL_49)),',')   END)

  + (CASE WHEN COL_50 IS NULL THEN '' ELSE CONCAT(SUBSTRING(COL_50,LEN(LEFT(COL_50, CHARINDEX('$', COL_50)+ 1)),LEN(COL_50)),',')   END)

  + (CASE WHEN COL_51 IS NULL THEN '' ELSE CONCAT(SUBSTRING(COL_51,LEN(LEFT(COL_51, CHARINDEX('$', COL_51)+ 1)),LEN(COL_51)),',')   END)

  + (CASE WHEN COL_52 IS NULL THEN '' ELSE CONCAT(SUBSTRING(COL_52,LEN(LEFT(COL_52, CHARINDEX('$', COL_52)+ 1)),LEN(COL_52)),',')   END)

  + (CASE WHEN COL_53 IS NULL THEN '' ELSE CONCAT(SUBSTRING(COL_53,LEN(LEFT(COL_53, CHARINDEX('$', COL_53)+ 1)),LEN(COL_53)),',')   END)

  + (CASE WHEN COL_54 IS NULL THEN '' ELSE CONCAT(SUBSTRING(COL_54,LEN(LEFT(COL_54, CHARINDEX('$', COL_54)+ 1)),LEN(COL_54)),',')   END)

  + (CASE WHEN COL_55 IS NULL THEN '' ELSE CONCAT(SUBSTRING(COL_55,LEN(LEFT(COL_55, CHARINDEX('$', COL_55)+ 1)),LEN(COL_55)),',')   END)

  + (CASE WHEN COL_56 IS NULL THEN '' ELSE CONCAT(SUBSTRING(COL_56,LEN(LEFT(COL_56, CHARINDEX('$', COL_56)+ 1)),LEN(COL_56)),',')   END)

  + (CASE WHEN COL_57 IS NULL THEN '' ELSE CONCAT(SUBSTRING(COL_57,LEN(LEFT(COL_57, CHARINDEX('$', COL_57)+ 1)),LEN(COL_57)),',')   END)

  + (CASE WHEN COL_58 IS NULL THEN '' ELSE CONCAT(SUBSTRING(COL_58,LEN(LEFT(COL_58, CHARINDEX('$', COL_58)+ 1)),LEN(COL_58)),',')   END)

  + (CASE WHEN COL_59 IS NULL THEN '' ELSE CONCAT(SUBSTRING(COL_59,LEN(LEFT(COL_59, CHARINDEX('$', COL_59)+ 1)),LEN(COL_59)),',')   END)

  + (CASE WHEN COL_60 IS NULL THEN '' ELSE CONCAT(SUBSTRING(COL_60,LEN(LEFT(COL_60, CHARINDEX('$', COL_60)+ 1)),LEN(COL_60)),',')   END)

  + (CASE WHEN COL_61 IS NULL THEN '' ELSE CONCAT(SUBSTRING(COL_61,LEN(LEFT(COL_61, CHARINDEX('$', COL_61)+ 1)),LEN(COL_61)),',')   END)

  + (CASE WHEN COL_62 IS NULL THEN '' ELSE CONCAT(SUBSTRING(COL_62,LEN(LEFT(COL_62, CHARINDEX('$', COL_62)+ 1)),LEN(COL_62)),',')   END)

  + (CASE WHEN COL_63 IS NULL THEN '' ELSE CONCAT(SUBSTRING(COL_63,LEN(LEFT(COL_63, CHARINDEX('$', COL_63)+ 1)),LEN(COL_63)),',')   END)

  + (CASE WHEN COL_64 IS NULL THEN '' ELSE CONCAT(SUBSTRING(COL_64,LEN(LEFT(COL_64, CHARINDEX('$', COL_64)+ 1)),LEN(COL_64)),',')   END)

  + (CASE WHEN COL_65 IS NULL THEN '' ELSE CONCAT(SUBSTRING(COL_65,LEN(LEFT(COL_65, CHARINDEX('$', COL_65)+ 1)),LEN(COL_65)),',')   END)

  + (CASE WHEN COL_66 IS NULL THEN '' ELSE CONCAT(SUBSTRING(COL_66,LEN(LEFT(COL_66, CHARINDEX('$', COL_66)+ 1)),LEN(COL_66)),',')   END)

  + (CASE WHEN COL_67 IS NULL THEN '' ELSE CONCAT(SUBSTRING(COL_67,LEN(LEFT(COL_67, CHARINDEX('$', COL_67)+ 1)),LEN(COL_67)),',')   END)

  + (CASE WHEN COL_68 IS NULL THEN '' ELSE CONCAT(SUBSTRING(COL_68,LEN(LEFT(COL_68, CHARINDEX('$', COL_68)+ 1)),LEN(COL_68)),',')   END)

  + (CASE WHEN COL_69 IS NULL THEN '' ELSE CONCAT(SUBSTRING(COL_69,LEN(LEFT(COL_69, CHARINDEX('$', COL_69)+ 1)),LEN(COL_69)),',')   END)

  + (CASE WHEN COL_70 IS NULL THEN '' ELSE CONCAT(SUBSTRING(COL_70,LEN(LEFT(COL_70, CHARINDEX('$', COL_70)+ 1)),LEN(COL_70)),',')   END)

  + (CASE WHEN COL_71 IS NULL THEN '' ELSE CONCAT(SUBSTRING(COL_71,LEN(LEFT(COL_71, CHARINDEX('$', COL_71)+ 1)),LEN(COL_71)),',')   END)

  + (CASE WHEN COL_72 IS NULL THEN '' ELSE CONCAT(SUBSTRING(COL_72,LEN(LEFT(COL_72, CHARINDEX('$', COL_72)+ 1)),LEN(COL_72)),',')   END)

  + (CASE WHEN COL_73 IS NULL THEN '' ELSE CONCAT(SUBSTRING(COL_73,LEN(LEFT(COL_73, CHARINDEX('$', COL_73)+ 1)),LEN(COL_73)),',')   END)

  + (CASE WHEN COL_74 IS NULL THEN '' ELSE CONCAT(SUBSTRING(COL_74,LEN(LEFT(COL_74, CHARINDEX('$', COL_74)+ 1)),LEN(COL_74)),',')   END)

  + (CASE WHEN COL_75 IS NULL THEN '' ELSE CONCAT(SUBSTRING(COL_75,LEN(LEFT(COL_75, CHARINDEX('$', COL_75)+ 1)),LEN(COL_75)),',')   END)

  + (CASE WHEN COL_76 IS NULL THEN '' ELSE CONCAT(SUBSTRING(COL_76,LEN(LEFT(COL_76, CHARINDEX('$', COL_76)+ 1)),LEN(COL_76)),',')   END)

  + (CASE WHEN COL_77 IS NULL THEN '' ELSE CONCAT(SUBSTRING(COL_77,LEN(LEFT(COL_77, CHARINDEX('$', COL_77)+ 1)),LEN(COL_77)),',')   END)

  + (CASE WHEN COL_78 IS NULL THEN '' ELSE CONCAT(SUBSTRING(COL_78,LEN(LEFT(COL_78, CHARINDEX('$', COL_78)+ 1)),LEN(COL_78)),',')   END)

  + (CASE WHEN COL_79 IS NULL THEN '' ELSE CONCAT(SUBSTRING(COL_79,LEN(LEFT(COL_79, CHARINDEX('$', COL_79)+ 1)),LEN(COL_79)),',')   END)

  + (CASE WHEN COL_80 IS NULL THEN '' ELSE CONCAT(SUBSTRING(COL_80,LEN(LEFT(COL_80, CHARINDEX('$', COL_80)+ 1)),LEN(COL_80)),',')   END)

  + (CASE WHEN COL_81 IS NULL THEN '' ELSE CONCAT(SUBSTRING(COL_81,LEN(LEFT(COL_81, CHARINDEX('$', COL_81)+ 1)),LEN(COL_81)),',')   END)

  + (CASE WHEN COL_82 IS NULL THEN '' ELSE CONCAT(SUBSTRING(COL_82,LEN(LEFT(COL_82, CHARINDEX('$', COL_82)+ 1)),LEN(COL_82)),',')   END)

  + (CASE WHEN COL_83 IS NULL THEN '' ELSE CONCAT(SUBSTRING(COL_83,LEN(LEFT(COL_83, CHARINDEX('$', COL_83)+ 1)),LEN(COL_83)),',')   END)

  + (CASE WHEN COL_84 IS NULL THEN '' ELSE CONCAT(SUBSTRING(COL_84,LEN(LEFT(COL_84, CHARINDEX('$', COL_84)+ 1)),LEN(COL_84)),',')   END)

  + (CASE WHEN COL_85 IS NULL THEN '' ELSE CONCAT(SUBSTRING(COL_85,LEN(LEFT(COL_85, CHARINDEX('$', COL_85)+ 1)),LEN(COL_85)),',')   END)

  + (CASE WHEN COL_86 IS NULL THEN '' ELSE CONCAT(SUBSTRING(COL_86,LEN(LEFT(COL_86, CHARINDEX('$', COL_86)+ 1)),LEN(COL_86)),',')   END)

  + (CASE WHEN COL_87 IS NULL THEN '' ELSE CONCAT(SUBSTRING(COL_87,LEN(LEFT(COL_87, CHARINDEX('$', COL_87)+ 1)),LEN(COL_87)),',')   END)

  + (CASE WHEN COL_88 IS NULL THEN '' ELSE CONCAT(SUBSTRING(COL_88,LEN(LEFT(COL_88, CHARINDEX('$', COL_88)+ 1)),LEN(COL_88)),',')   END)

  + (CASE WHEN COL_89 IS NULL THEN '' ELSE CONCAT(SUBSTRING(COL_89,LEN(LEFT(COL_89, CHARINDEX('$', COL_89)+ 1)),LEN(COL_89)),',')   END)

  + (CASE WHEN COL_90 IS NULL THEN '' ELSE CONCAT(SUBSTRING(COL_90,LEN(LEFT(COL_90, CHARINDEX('$', COL_90)+ 1)),LEN(COL_90)),',')   END)

  + (CASE WHEN COL_91 IS NULL THEN '' ELSE CONCAT(SUBSTRING(COL_91,LEN(LEFT(COL_91, CHARINDEX('$', COL_91)+ 1)),LEN(COL_91)),',')   END)

  + (CASE WHEN COL_92 IS NULL THEN '' ELSE CONCAT(SUBSTRING(COL_92,LEN(LEFT(COL_92, CHARINDEX('$', COL_92)+ 1)),LEN(COL_92)),',')   END)

  + (CASE WHEN COL_93 IS NULL THEN '' ELSE CONCAT(SUBSTRING(COL_93,LEN(LEFT(COL_93, CHARINDEX('$', COL_93)+ 1)),LEN(COL_93)),',')   END)

  + (CASE WHEN COL_94 IS NULL THEN '' ELSE CONCAT(SUBSTRING(COL_94,LEN(LEFT(COL_94, CHARINDEX('$', COL_94)+ 1)),LEN(COL_94)),',')   END)

  + (CASE WHEN COL_95 IS NULL THEN '' ELSE CONCAT(SUBSTRING(COL_95,LEN(LEFT(COL_95, CHARINDEX('$', COL_95)+ 1)),LEN(COL_95)),',')   END)

  + (CASE WHEN COL_96 IS NULL THEN '' ELSE CONCAT(SUBSTRING(COL_96,LEN(LEFT(COL_96, CHARINDEX('$', COL_96)+ 1)),LEN(COL_96)),',')   END)

  + (CASE WHEN COL_97 IS NULL THEN '' ELSE CONCAT(SUBSTRING(COL_97,LEN(LEFT(COL_97, CHARINDEX('$', COL_97)+ 1)),LEN(COL_97)),',')   END)

  + (CASE WHEN COL_98 IS NULL THEN '' ELSE CONCAT(SUBSTRING(COL_98,LEN(LEFT(COL_98, CHARINDEX('$', COL_98)+ 1)),LEN(COL_98)),',')   END)

  + (CASE WHEN COL_99 IS NULL THEN '' ELSE CONCAT(SUBSTRING(COL_99,LEN(LEFT(COL_99, CHARINDEX('$', COL_99)+ 1)),LEN(COL_99)),',')   END)) 

from [DATA_SECURITY].[dbo].[CBA_TABLES_TANG] where id=@table_id

print(@old_table_colum_list)

declare @DynamicSQL_2 varchar(max)

set @new_column_name =left(@new_column_name, len(@new_column_name)-1) 

set @old_table_colum_list =left(@old_table_colum_list, len(@old_table_colum_list)-1)

set @old_table_colum_list=concat(concat('(',@old_table_colum_list,' ',''),')')

--set @old_table_colum_list=replace(replace(@old_table_colum_list,',','],['),' ','')


DECLARE @NEW_GET_VARIBLE_LIST NVARCHAR(MAX)

declare @out nvarchar(max)

set @out=''

select @out=concat(@out,case when  @old_table_colum_list like '%'+col_01+'%'  then 'COL_01,' ELSE '' END) FROM [DATA_SECURITY].[dbo].[CBA_TABLES] WHERE TABLE_NAME=@targested_table_name

select @out=concat(@out,case when  @old_table_colum_list like '%'+col_02+'%'  then 'COL_02,' ELSE '' END) FROM [DATA_SECURITY].[dbo].[CBA_TABLES] WHERE TABLE_NAME=@targested_table_name

select @out=concat(@out,case when  @old_table_colum_list like '%'+col_03+'%'  then 'COL_03,' ELSE '' END) FROM [DATA_SECURITY].[dbo].[CBA_TABLES] WHERE TABLE_NAME=@targested_table_name

select @out=concat(@out,case when  @old_table_colum_list like '%'+col_04+'%'  then 'COL_04,' ELSE '' END) FROM [DATA_SECURITY].[dbo].[CBA_TABLES] WHERE TABLE_NAME=@targested_table_name

select @out=concat(@out,case when  @old_table_colum_list like '%'+col_05+'%'  then 'COL_05,' ELSE '' END) FROM [DATA_SECURITY].[dbo].[CBA_TABLES] WHERE TABLE_NAME=@targested_table_name

select @out=concat(@out,case when  @old_table_colum_list like '%'+col_06+'%'  then 'COL_06,' ELSE '' END) FROM [DATA_SECURITY].[dbo].[CBA_TABLES] WHERE TABLE_NAME=@targested_table_name

select @out=concat(@out,case when  @old_table_colum_list like '%'+col_07+'%'  then 'COL_07,' ELSE '' END) FROM [DATA_SECURITY].[dbo].[CBA_TABLES] WHERE TABLE_NAME=@targested_table_name

select @out=concat(@out,case when  @old_table_colum_list like '%'+col_08+'%'  then 'COL_08,' ELSE '' END) FROM [DATA_SECURITY].[dbo].[CBA_TABLES] WHERE TABLE_NAME=@targested_table_name

select @out=concat(@out,case when  @old_table_colum_list like '%'+col_09+'%'  then 'COL_09,' ELSE '' END) FROM [DATA_SECURITY].[dbo].[CBA_TABLES] WHERE TABLE_NAME=@targested_table_name

select @out=concat(@out,case when  @old_table_colum_list like '%'+col_10+'%'  then 'COL_10,' ELSE '' END) FROM [DATA_SECURITY].[dbo].[CBA_TABLES] WHERE TABLE_NAME=@targested_table_name

select @out=concat(@out,case when  @old_table_colum_list like '%'+col_11+'%'  then 'COL_11,' ELSE '' END) FROM [DATA_SECURITY].[dbo].[CBA_TABLES] WHERE TABLE_NAME=@targested_table_name

select @out=concat(@out,case when  @old_table_colum_list like '%'+col_12+'%'  then 'COL_12,' ELSE '' END) FROM [DATA_SECURITY].[dbo].[CBA_TABLES] WHERE TABLE_NAME=@targested_table_name

select @out=concat(@out,case when  @old_table_colum_list like '%'+col_13+'%'  then 'COL_13,' ELSE '' END) FROM [DATA_SECURITY].[dbo].[CBA_TABLES] WHERE TABLE_NAME=@targested_table_name

select @out=concat(@out,case when  @old_table_colum_list like '%'+col_14+'%'  then 'COL_14,' ELSE '' END) FROM [DATA_SECURITY].[dbo].[CBA_TABLES] WHERE TABLE_NAME=@targested_table_name

select @out=concat(@out,case when  @old_table_colum_list like '%'+col_15+'%'  then 'COL_15,' ELSE '' END) FROM [DATA_SECURITY].[dbo].[CBA_TABLES] WHERE TABLE_NAME=@targested_table_name

select @out=concat(@out,case when  @old_table_colum_list like '%'+col_16+'%'  then 'COL_16,' ELSE '' END) FROM [DATA_SECURITY].[dbo].[CBA_TABLES] WHERE TABLE_NAME=@targested_table_name

select @out=concat(@out,case when  @old_table_colum_list like '%'+col_17+'%'  then 'COL_17,' ELSE '' END) FROM [DATA_SECURITY].[dbo].[CBA_TABLES] WHERE TABLE_NAME=@targested_table_name

select @out=concat(@out,case when  @old_table_colum_list like '%'+col_18+'%'  then 'COL_18,' ELSE '' END) FROM [DATA_SECURITY].[dbo].[CBA_TABLES] WHERE TABLE_NAME=@targested_table_name

select @out=concat(@out,case when  @old_table_colum_list like '%'+col_19+'%'  then 'COL_19,' ELSE '' END) FROM [DATA_SECURITY].[dbo].[CBA_TABLES] WHERE TABLE_NAME=@targested_table_name

select @out=concat(@out,case when  @old_table_colum_list like '%'+col_20+'%'  then 'COL_20,' ELSE '' END) FROM [DATA_SECURITY].[dbo].[CBA_TABLES] WHERE TABLE_NAME=@targested_table_name

select @out=concat(@out,case when  @old_table_colum_list like '%'+col_21+'%'  then 'COL_21,' ELSE '' END) FROM [DATA_SECURITY].[dbo].[CBA_TABLES] WHERE TABLE_NAME=@targested_table_name

select @out=concat(@out,case when  @old_table_colum_list like '%'+col_22+'%'  then 'COL_22,' ELSE '' END) FROM [DATA_SECURITY].[dbo].[CBA_TABLES] WHERE TABLE_NAME=@targested_table_name

select @out=concat(@out,case when  @old_table_colum_list like '%'+col_23+'%'  then 'COL_23,' ELSE '' END) FROM [DATA_SECURITY].[dbo].[CBA_TABLES] WHERE TABLE_NAME=@targested_table_name

select @out=concat(@out,case when  @old_table_colum_list like '%'+col_24+'%'  then 'COL_24,' ELSE '' END) FROM [DATA_SECURITY].[dbo].[CBA_TABLES] WHERE TABLE_NAME=@targested_table_name

select @out=concat(@out,case when  @old_table_colum_list like '%'+col_25+'%'  then 'COL_25,' ELSE '' END) FROM [DATA_SECURITY].[dbo].[CBA_TABLES] WHERE TABLE_NAME=@targested_table_name

select @out=concat(@out,case when  @old_table_colum_list like '%'+col_26+'%'  then 'COL_26,' ELSE '' END) FROM [DATA_SECURITY].[dbo].[CBA_TABLES] WHERE TABLE_NAME=@targested_table_name

select @out=concat(@out,case when  @old_table_colum_list like '%'+col_27+'%'  then 'COL_27,' ELSE '' END) FROM [DATA_SECURITY].[dbo].[CBA_TABLES] WHERE TABLE_NAME=@targested_table_name

select @out=concat(@out,case when  @old_table_colum_list like '%'+col_28+'%'  then 'COL_28,' ELSE '' END) FROM [DATA_SECURITY].[dbo].[CBA_TABLES] WHERE TABLE_NAME=@targested_table_name

select @out=concat(@out,case when  @old_table_colum_list like '%'+col_29+'%'  then 'COL_29,' ELSE '' END) FROM [DATA_SECURITY].[dbo].[CBA_TABLES] WHERE TABLE_NAME=@targested_table_name

select @out=concat(@out,case when  @old_table_colum_list like '%'+col_30+'%'  then 'COL_30,' ELSE '' END) FROM [DATA_SECURITY].[dbo].[CBA_TABLES] WHERE TABLE_NAME=@targested_table_name

select @out=concat(@out,case when  @old_table_colum_list like '%'+col_31+'%'  then 'COL_31,' ELSE '' END) FROM [DATA_SECURITY].[dbo].[CBA_TABLES] WHERE TABLE_NAME=@targested_table_name

select @out=concat(@out,case when  @old_table_colum_list like '%'+col_32+'%'  then 'COL_32,' ELSE '' END) FROM [DATA_SECURITY].[dbo].[CBA_TABLES] WHERE TABLE_NAME=@targested_table_name

select @out=concat(@out,case when  @old_table_colum_list like '%'+col_33+'%'  then 'COL_33,' ELSE '' END) FROM [DATA_SECURITY].[dbo].[CBA_TABLES] WHERE TABLE_NAME=@targested_table_name

select @out=concat(@out,case when  @old_table_colum_list like '%'+col_34+'%'  then 'COL_34,' ELSE '' END) FROM [DATA_SECURITY].[dbo].[CBA_TABLES] WHERE TABLE_NAME=@targested_table_name

select @out=concat(@out,case when  @old_table_colum_list like '%'+col_35+'%'  then 'COL_35,' ELSE '' END) FROM [DATA_SECURITY].[dbo].[CBA_TABLES] WHERE TABLE_NAME=@targested_table_name

select @out=concat(@out,case when  @old_table_colum_list like '%'+col_36+'%'  then 'COL_36,' ELSE '' END) FROM [DATA_SECURITY].[dbo].[CBA_TABLES] WHERE TABLE_NAME=@targested_table_name

select @out=concat(@out,case when  @old_table_colum_list like '%'+col_37+'%'  then 'COL_37,' ELSE '' END) FROM [DATA_SECURITY].[dbo].[CBA_TABLES] WHERE TABLE_NAME=@targested_table_name

select @out=concat(@out,case when  @old_table_colum_list like '%'+col_38+'%'  then 'COL_38,' ELSE '' END) FROM [DATA_SECURITY].[dbo].[CBA_TABLES] WHERE TABLE_NAME=@targested_table_name

select @out=concat(@out,case when  @old_table_colum_list like '%'+col_39+'%'  then 'COL_39,' ELSE '' END) FROM [DATA_SECURITY].[dbo].[CBA_TABLES] WHERE TABLE_NAME=@targested_table_name

select @out=concat(@out,case when  @old_table_colum_list like '%'+col_40+'%'  then 'COL_40,' ELSE '' END) FROM [DATA_SECURITY].[dbo].[CBA_TABLES] WHERE TABLE_NAME=@targested_table_name

select @out=concat(@out,case when  @old_table_colum_list like '%'+col_41+'%'  then 'COL_41,' ELSE '' END) FROM [DATA_SECURITY].[dbo].[CBA_TABLES] WHERE TABLE_NAME=@targested_table_name

select @out=concat(@out,case when  @old_table_colum_list like '%'+col_42+'%'  then 'COL_42,' ELSE '' END) FROM [DATA_SECURITY].[dbo].[CBA_TABLES] WHERE TABLE_NAME=@targested_table_name

select @out=concat(@out,case when  @old_table_colum_list like '%'+col_43+'%'  then 'COL_43,' ELSE '' END) FROM [DATA_SECURITY].[dbo].[CBA_TABLES] WHERE TABLE_NAME=@targested_table_name

select @out=concat(@out,case when  @old_table_colum_list like '%'+col_44+'%'  then 'COL_44,' ELSE '' END) FROM [DATA_SECURITY].[dbo].[CBA_TABLES] WHERE TABLE_NAME=@targested_table_name

select @out=concat(@out,case when  @old_table_colum_list like '%'+col_45+'%'  then 'COL_45,' ELSE '' END) FROM [DATA_SECURITY].[dbo].[CBA_TABLES] WHERE TABLE_NAME=@targested_table_name

select @out=concat(@out,case when  @old_table_colum_list like '%'+col_46+'%'  then 'COL_46,' ELSE '' END) FROM [DATA_SECURITY].[dbo].[CBA_TABLES] WHERE TABLE_NAME=@targested_table_name

select @out=concat(@out,case when  @old_table_colum_list like '%'+col_47+'%'  then 'COL_47,' ELSE '' END) FROM [DATA_SECURITY].[dbo].[CBA_TABLES] WHERE TABLE_NAME=@targested_table_name

select @out=concat(@out,case when  @old_table_colum_list like '%'+col_48+'%'  then 'COL_48,' ELSE '' END) FROM [DATA_SECURITY].[dbo].[CBA_TABLES] WHERE TABLE_NAME=@targested_table_name

select @out=concat(@out,case when  @old_table_colum_list like '%'+col_49+'%'  then 'COL_49,' ELSE '' END) FROM [DATA_SECURITY].[dbo].[CBA_TABLES] WHERE TABLE_NAME=@targested_table_name

select @out=concat(@out,case when  @old_table_colum_list like '%'+col_50+'%'  then 'COL_50,' ELSE '' END) FROM [DATA_SECURITY].[dbo].[CBA_TABLES] WHERE TABLE_NAME=@targested_table_name

select @out=concat(@out,case when  @old_table_colum_list like '%'+col_51+'%'  then 'COL_51,' ELSE '' END) FROM [DATA_SECURITY].[dbo].[CBA_TABLES] WHERE TABLE_NAME=@targested_table_name

select @out=concat(@out,case when  @old_table_colum_list like '%'+col_52+'%'  then 'COL_52,' ELSE '' END) FROM [DATA_SECURITY].[dbo].[CBA_TABLES] WHERE TABLE_NAME=@targested_table_name

select @out=concat(@out,case when  @old_table_colum_list like '%'+col_53+'%'  then 'COL_53,' ELSE '' END) FROM [DATA_SECURITY].[dbo].[CBA_TABLES] WHERE TABLE_NAME=@targested_table_name

select @out=concat(@out,case when  @old_table_colum_list like '%'+col_54+'%'  then 'COL_54,' ELSE '' END) FROM [DATA_SECURITY].[dbo].[CBA_TABLES] WHERE TABLE_NAME=@targested_table_name

select @out=concat(@out,case when  @old_table_colum_list like '%'+col_55+'%'  then 'COL_55,' ELSE '' END) FROM [DATA_SECURITY].[dbo].[CBA_TABLES] WHERE TABLE_NAME=@targested_table_name

select @out=concat(@out,case when  @old_table_colum_list like '%'+col_56+'%'  then 'COL_56,' ELSE '' END) FROM [DATA_SECURITY].[dbo].[CBA_TABLES] WHERE TABLE_NAME=@targested_table_name

select @out=concat(@out,case when  @old_table_colum_list like '%'+col_57+'%'  then 'COL_57,' ELSE '' END) FROM [DATA_SECURITY].[dbo].[CBA_TABLES] WHERE TABLE_NAME=@targested_table_name

select @out=concat(@out,case when  @old_table_colum_list like '%'+col_58+'%'  then 'COL_58,' ELSE '' END) FROM [DATA_SECURITY].[dbo].[CBA_TABLES] WHERE TABLE_NAME=@targested_table_name

select @out=concat(@out,case when  @old_table_colum_list like '%'+col_59+'%'  then 'COL_59,' ELSE '' END) FROM [DATA_SECURITY].[dbo].[CBA_TABLES] WHERE TABLE_NAME=@targested_table_name

select @out=concat(@out,case when  @old_table_colum_list like '%'+col_60+'%'  then 'COL_60,' ELSE '' END) FROM [DATA_SECURITY].[dbo].[CBA_TABLES] WHERE TABLE_NAME=@targested_table_name

select @out=concat(@out,case when  @old_table_colum_list like '%'+col_61+'%'  then 'COL_61,' ELSE '' END) FROM [DATA_SECURITY].[dbo].[CBA_TABLES] WHERE TABLE_NAME=@targested_table_name

select @out=concat(@out,case when  @old_table_colum_list like '%'+col_62+'%'  then 'COL_62,' ELSE '' END) FROM [DATA_SECURITY].[dbo].[CBA_TABLES] WHERE TABLE_NAME=@targested_table_name

select @out=concat(@out,case when  @old_table_colum_list like '%'+col_63+'%'  then 'COL_63,' ELSE '' END) FROM [DATA_SECURITY].[dbo].[CBA_TABLES] WHERE TABLE_NAME=@targested_table_name

select @out=concat(@out,case when  @old_table_colum_list like '%'+col_64+'%'  then 'COL_64,' ELSE '' END) FROM [DATA_SECURITY].[dbo].[CBA_TABLES] WHERE TABLE_NAME=@targested_table_name

select @out=concat(@out,case when  @old_table_colum_list like '%'+col_65+'%'  then 'COL_65,' ELSE '' END) FROM [DATA_SECURITY].[dbo].[CBA_TABLES] WHERE TABLE_NAME=@targested_table_name

select @out=concat(@out,case when  @old_table_colum_list like '%'+col_66+'%'  then 'COL_66,' ELSE '' END) FROM [DATA_SECURITY].[dbo].[CBA_TABLES] WHERE TABLE_NAME=@targested_table_name

select @out=concat(@out,case when  @old_table_colum_list like '%'+col_67+'%'  then 'COL_67,' ELSE '' END) FROM [DATA_SECURITY].[dbo].[CBA_TABLES] WHERE TABLE_NAME=@targested_table_name

select @out=concat(@out,case when  @old_table_colum_list like '%'+col_68+'%'  then 'COL_68,' ELSE '' END) FROM [DATA_SECURITY].[dbo].[CBA_TABLES] WHERE TABLE_NAME=@targested_table_name

select @out=concat(@out,case when  @old_table_colum_list like '%'+col_69+'%'  then 'COL_69,' ELSE '' END) FROM [DATA_SECURITY].[dbo].[CBA_TABLES] WHERE TABLE_NAME=@targested_table_name

select @out=concat(@out,case when  @old_table_colum_list like '%'+col_70+'%'  then 'COL_70,' ELSE '' END) FROM [DATA_SECURITY].[dbo].[CBA_TABLES] WHERE TABLE_NAME=@targested_table_name

select @out=concat(@out,case when  @old_table_colum_list like '%'+col_71+'%'  then 'COL_71,' ELSE '' END) FROM [DATA_SECURITY].[dbo].[CBA_TABLES] WHERE TABLE_NAME=@targested_table_name

select @out=concat(@out,case when  @old_table_colum_list like '%'+col_72+'%'  then 'COL_72,' ELSE '' END) FROM [DATA_SECURITY].[dbo].[CBA_TABLES] WHERE TABLE_NAME=@targested_table_name

select @out=concat(@out,case when  @old_table_colum_list like '%'+col_73+'%'  then 'COL_73,' ELSE '' END) FROM [DATA_SECURITY].[dbo].[CBA_TABLES] WHERE TABLE_NAME=@targested_table_name

select @out=concat(@out,case when  @old_table_colum_list like '%'+col_74+'%'  then 'COL_74,' ELSE '' END) FROM [DATA_SECURITY].[dbo].[CBA_TABLES] WHERE TABLE_NAME=@targested_table_name

select @out=concat(@out,case when  @old_table_colum_list like '%'+col_75+'%'  then 'COL_75,' ELSE '' END) FROM [DATA_SECURITY].[dbo].[CBA_TABLES] WHERE TABLE_NAME=@targested_table_name

select @out=concat(@out,case when  @old_table_colum_list like '%'+col_76+'%'  then 'COL_76,' ELSE '' END) FROM [DATA_SECURITY].[dbo].[CBA_TABLES] WHERE TABLE_NAME=@targested_table_name

select @out=concat(@out,case when  @old_table_colum_list like '%'+col_77+'%'  then 'COL_77,' ELSE '' END) FROM [DATA_SECURITY].[dbo].[CBA_TABLES] WHERE TABLE_NAME=@targested_table_name

select @out=concat(@out,case when  @old_table_colum_list like '%'+col_78+'%'  then 'COL_78,' ELSE '' END) FROM [DATA_SECURITY].[dbo].[CBA_TABLES] WHERE TABLE_NAME=@targested_table_name

select @out=concat(@out,case when  @old_table_colum_list like '%'+col_79+'%'  then 'COL_79,' ELSE '' END) FROM [DATA_SECURITY].[dbo].[CBA_TABLES] WHERE TABLE_NAME=@targested_table_name

select @out=concat(@out,case when  @old_table_colum_list like '%'+col_80+'%'  then 'COL_80,' ELSE '' END) FROM [DATA_SECURITY].[dbo].[CBA_TABLES] WHERE TABLE_NAME=@targested_table_name

select @out=concat(@out,case when  @old_table_colum_list like '%'+col_81+'%'  then 'COL_81,' ELSE '' END) FROM [DATA_SECURITY].[dbo].[CBA_TABLES] WHERE TABLE_NAME=@targested_table_name

select @out=concat(@out,case when  @old_table_colum_list like '%'+col_82+'%'  then 'COL_82,' ELSE '' END) FROM [DATA_SECURITY].[dbo].[CBA_TABLES] WHERE TABLE_NAME=@targested_table_name

select @out=concat(@out,case when  @old_table_colum_list like '%'+col_83+'%'  then 'COL_83,' ELSE '' END) FROM [DATA_SECURITY].[dbo].[CBA_TABLES] WHERE TABLE_NAME=@targested_table_name

select @out=concat(@out,case when  @old_table_colum_list like '%'+col_84+'%'  then 'COL_84,' ELSE '' END) FROM [DATA_SECURITY].[dbo].[CBA_TABLES] WHERE TABLE_NAME=@targested_table_name

select @out=concat(@out,case when  @old_table_colum_list like '%'+col_85+'%'  then 'COL_85,' ELSE '' END) FROM [DATA_SECURITY].[dbo].[CBA_TABLES] WHERE TABLE_NAME=@targested_table_name

select @out=concat(@out,case when  @old_table_colum_list like '%'+col_86+'%'  then 'COL_86,' ELSE '' END) FROM [DATA_SECURITY].[dbo].[CBA_TABLES] WHERE TABLE_NAME=@targested_table_name

select @out=concat(@out,case when  @old_table_colum_list like '%'+col_87+'%'  then 'COL_87,' ELSE '' END) FROM [DATA_SECURITY].[dbo].[CBA_TABLES] WHERE TABLE_NAME=@targested_table_name

select @out=concat(@out,case when  @old_table_colum_list like '%'+col_88+'%'  then 'COL_88,' ELSE '' END) FROM [DATA_SECURITY].[dbo].[CBA_TABLES] WHERE TABLE_NAME=@targested_table_name

select @out=concat(@out,case when  @old_table_colum_list like '%'+col_89+'%'  then 'COL_89,' ELSE '' END) FROM [DATA_SECURITY].[dbo].[CBA_TABLES] WHERE TABLE_NAME=@targested_table_name

select @out=concat(@out,case when  @old_table_colum_list like '%'+col_90+'%'  then 'COL_90,' ELSE '' END) FROM [DATA_SECURITY].[dbo].[CBA_TABLES] WHERE TABLE_NAME=@targested_table_name

select @out=concat(@out,case when  @old_table_colum_list like '%'+col_91+'%'  then 'COL_91,' ELSE '' END) FROM [DATA_SECURITY].[dbo].[CBA_TABLES] WHERE TABLE_NAME=@targested_table_name

select @out=concat(@out,case when  @old_table_colum_list like '%'+col_92+'%'  then 'COL_92,' ELSE '' END) FROM [DATA_SECURITY].[dbo].[CBA_TABLES] WHERE TABLE_NAME=@targested_table_name

select @out=concat(@out,case when  @old_table_colum_list like '%'+col_93+'%'  then 'COL_93,' ELSE '' END) FROM [DATA_SECURITY].[dbo].[CBA_TABLES] WHERE TABLE_NAME=@targested_table_name

select @out=concat(@out,case when  @old_table_colum_list like '%'+col_94+'%'  then 'COL_94,' ELSE '' END) FROM [DATA_SECURITY].[dbo].[CBA_TABLES] WHERE TABLE_NAME=@targested_table_name

select @out=concat(@out,case when  @old_table_colum_list like '%'+col_95+'%'  then 'COL_95,' ELSE '' END) FROM [DATA_SECURITY].[dbo].[CBA_TABLES] WHERE TABLE_NAME=@targested_table_name

select @out=concat(@out,case when  @old_table_colum_list like '%'+col_96+'%'  then 'COL_96,' ELSE '' END) FROM [DATA_SECURITY].[dbo].[CBA_TABLES] WHERE TABLE_NAME=@targested_table_name

select @out=concat(@out,case when  @old_table_colum_list like '%'+col_97+'%'  then 'COL_97,' ELSE '' END) FROM [DATA_SECURITY].[dbo].[CBA_TABLES] WHERE TABLE_NAME=@targested_table_name

select @out=concat(@out,case when  @old_table_colum_list like '%'+col_98+'%'  then 'COL_98,' ELSE '' END) FROM [DATA_SECURITY].[dbo].[CBA_TABLES] WHERE TABLE_NAME=@targested_table_name

select @out=concat(@out,case when  @old_table_colum_list like '%'+col_99+'%'  then 'COL_99,' ELSE '' END) FROM [DATA_SECURITY].[dbo].[CBA_TABLES] WHERE TABLE_NAME=@targested_table_name

set @out= substring(@out,0,len(@out))

set @new_table_colum_list=substring(@new_table_colum_list,0,len(@new_table_colum_list))


print(@new_table_colum_list)

print(@out)

select * from #Excel_data

SET   @DynamicSQL_2 = 'insert into '+@new_table_name+'('+ @new_table_colum_list +')  select '+@out+' from #Excel_data'

EXEC(@DynamicSQL_2)

drop table #Excel_data







Thursday, June 23, 2022

SQL SERVER DBA

Working Environment Types

1- Production

2- QA

3- Development

Database Restore Types
1- Full Backup

2- Differential 

3- LOG BACKUP

Process
- with Standby– Read only Database will be restored

-with norecovery- when we required to restore the data of full and differential backup only

-with recovery- when we required to store the database till crash time


1- Norecovery- Full Not Access
2- Norecovery-  Differential not Access

3- Recovery- Log Backup Access

Info -MSDB database
RestoreFile
RestoreFileGroup
RestoreHistory


DATABASE BACKUP-

FULL-
Backup DATABASE SAWAN TO DISK=’SAWAN_FULL_BACKUP_07_06_2022.BAK’  WITH INIT



DIFFERNTIAL -

 Backup DATABASE SAWAN TO DISK=’SAWAN_DIFF_BACKUP_07_06_2022.BAK’  WITH DIFFERENTIAL,  INIT


LOG BACKUP-

BACKUP LOG SAWAN TO DISK=’SAWAN_LOG’ WITH NO_TRUNCATE


RESTORE
1- RESTORE DATABASE SAWAN FROM DISK=’’ WITH NORECOVERY


File Group Backup
Split
Mirrod
Copy only Backup


DR Plan
1-Loggshipping

2-Mirroring
3-Aloways On

4- Clustering

5-Replication
ITIL-SLA


Friday, May 6, 2022

SQL Important Scripts

 To create a new table and load the data directly


select  Param1

      ,Param2

      ,Param3

      ,Param4

      ,Param5

      ,Param6

      ,Param7

INTO New_Table_Name   FROM

 OLD_TABLE_NAME where month(created_on)=4


Translate