SCHEMA PREVIEW
ELE_SALE_CUSTOM_ORDER
Xem trước DDL trước khi tạo hoặc bổ sung cột an toàn trên SQL Server.
SQL Server DDL
Chỉ tự động tạo schema/table/index và thêm cột nullable còn thiếu.
IF SCHEMA_ID(N'stg') IS NULL EXEC(N'CREATE SCHEMA [stg]');
IF SCHEMA_ID(N'ods') IS NULL EXEC(N'CREATE SCHEMA [ods]');
IF SCHEMA_ID(N'hist') IS NULL EXEC(N'CREATE SCHEMA [hist]');
IF OBJECT_ID(N'stg.J11_ele_sale_custom_order', N'U') IS NULL
BEGIN
CREATE TABLE [stg].[J11_ele_sale_custom_order]
(
[id] int NULL,
[campaign_id] int NULL,
[source_id] int NULL,
[medium_id] int NULL,
[company_id] int NULL,
[partner_id] int NULL,
[journal_id] int NULL,
[partner_invoice_id] int NULL,
[partner_shipping_id] int NULL,
[fiscal_position_id] int NULL,
[payment_term_id] int NULL,
[pricelist_id] int NULL,
[currency_id] int NULL,
[user_id] int NULL,
[team_id] int NULL,
[workflow_id] int NULL,
[current_sequence] int NULL,
[SlpCode] int NULL,
[GroupNum] int NULL,
[WhsCode] int NULL,
[Project] int NULL,
[marketing_campaign_id] int NULL,
[cntct_code] int NULL,
[ShipToCode] int NULL,
[CardCode2] int NULL,
[create_uid] int NULL,
[write_uid] int NULL,
[access_token] nvarchar(max) NULL,
[name] nvarchar(max) NULL,
[state] nvarchar(max) NULL,
[client_order_ref] nvarchar(max) NULL,
[origin] nvarchar(max) NULL,
[reference] nvarchar(max) NULL,
[signed_by] nvarchar(max) NULL,
[invoice_status] nvarchar(max) NULL,
[VoucherTypeID] nvarchar(max) NULL,
[CardCode] nvarchar(max) NULL,
[TrnspCode] nvarchar(max) NULL,
[BPLId] nvarchar(max) NULL,
[Store] nvarchar(max) NULL,
[InvStore] nvarchar(max) NULL,
[BusinessArea] nvarchar(max) NULL,
[S1No] nvarchar(max) NULL,
[VoucherNo] nvarchar(max) NULL,
[StatusID] nvarchar(max) NULL,
[vat] nvarchar(max) NULL,
[EL_Construction_Code] nvarchar(max) NULL,
[EL_PowerGearlessCabinet] nvarchar(max) NULL,
[EL_PowerGearlessCabinet_Note] nvarchar(max) NULL,
[EL_QuantityStops] nvarchar(max) NULL,
[EL_Speed] nvarchar(max) NULL,
[EL_Speed_Note] nvarchar(max) NULL,
[EL_QuantityGroup] nvarchar(max) NULL,
[EL_QuantityGroup_Note] nvarchar(max) NULL,
[EL_TractorBrakeVoltage] nvarchar(max) NULL,
[EL_TractorBrakeVoltage_Note] nvarchar(max) NULL,
[EL_Encoder] nvarchar(max) NULL,
[EL_Trademark] nvarchar(max) NULL,
[report_type] nvarchar(max) NULL,
[validity_date] datetime2(6) NULL,
[PostingDate] date NULL,
[DocDueDate] date NULL,
[quote_date] date NULL,
[order_date] date NULL,
[expected_delivery_date] date NULL,
[actual_delivery_date] date NULL,
[note] nvarchar(max) NULL,
[NoteInternal] nvarchar(max) NULL,
[Comments] nvarchar(max) NULL,
[NoteForAct] nvarchar(max) NULL,
[currency_rate] decimal(38,10) NULL,
[amount_untaxed] decimal(38,10) NULL,
[amount_tax] decimal(38,10) NULL,
[amount_total] decimal(38,10) NULL,
[locked] bit NULL,
[require_signature] bit NULL,
[require_payment] bit NULL,
[promotion_is_applied] bit NULL,
[IsIssueInvoice] bit NULL,
[IsCOD] bit NULL,
[IsCOCQ] bit NULL,
[IsInstall] bit NULL,
[IsSetup] bit NULL,
[create_date] datetime2(6) NULL,
[commitment_date] datetime2(6) NULL,
[date_order] datetime2(6) NULL,
[signed_on] datetime2(6) NULL,
[write_date] datetime2(6) NULL,
[prepayment_percent] float NULL,
[max_discount] float NULL,
[company_ref] nvarchar(max) NULL,
[trnsp_id] int NULL,
[blanket_agreement_id] int NULL,
[u_is_issue_invoice] nvarchar(max) NULL,
[docnumber] nvarchar(max) NULL,
[credit_notice] nvarchar(max) NULL,
[sap_stt] int NULL,
[sap_u_sino] nvarchar(max) NULL,
[sap_opty_type] nvarchar(max) NULL,
[sap_voucher_no] nvarchar(max) NULL,
[sap_status_name] nvarchar(max) NULL,
[EL_Construction_Address] nvarchar(max) NULL,
[partner_ref] nvarchar(max) NULL,
[u_carcodecommission] int NULL,
[dispatch_notified_by] int NULL,
[so_create_result] nvarchar(max) NULL,
[so_create_lock_uuid] nvarchar(max) NULL,
[so_idem_key] nvarchar(max) NULL,
[dispatch_state] nvarchar(max) NULL,
[dispatch_webhook_key] nvarchar(max) NULL,
[dispatch_note] nvarchar(max) NULL,
[is_fully_stocked] bit NULL,
[so_create_attempted] bit NULL,
[has_commission_line] bit NULL,
[eta_datetime] datetime2(6) NULL,
[so_create_attempted_at] datetime2(6) NULL,
[dispatch_notified_at] datetime2(6) NULL,
[dispatch_send_count] int NULL,
[pay_last_remark] nvarchar(max) NULL,
[pay_updated_at] datetime2(6) NULL,
[pay_accumulated] float NULL,
[pay_last_amount] float NULL,
[sap_completed_at_hist] nvarchar(max) NULL,
[sap_completed_at] datetime2(6) NULL,
[credit_auto_pass] bit NULL,
[auto_be_promotion_log] nvarchar(max) NULL,
[auto_be_promotion_last_sync] datetime2(6) NULL,
[promotion_reason_id] int NULL,
[oms_eta_warning_message] nvarchar(max) NULL,
[oms_dispatch_eta_notified] bit NULL,
[oms_dispatch_upcoming_notified] bit NULL,
[oms_has_eta_adjustment] bit NULL,
[oms_eta_exceeds_delivery] bit NULL,
[oms_submitted_for_approval_at] datetime2(6) NULL,
[oms_credit_approved_at] datetime2(6) NULL,
[oms_max_eta_done] datetime2(6) NULL,
[oms_eta_sla_deadline] datetime2(6) NULL,
[oms_eta_sla_hours] float NULL,
[approval_rejected_step_name] nvarchar(max) NULL,
[oms_late_dispatch_alert_sent] bit NULL,
[oms_late_dispatch_alert_sent_at] datetime2(6) NULL,
[so_create_lock_at] datetime2(6) NULL,
[EL_Elevator_Code] nvarchar(max) NULL,
[sap_inv_no] nvarchar(max) NULL,
[sap_status_sync_error] nvarchar(max) NULL,
[sap_status_sync_at] datetime2(6) NULL,
[sync_source_id] int NOT NULL,
[sync_job_id] int NOT NULL,
[sync_run_id] bigint NOT NULL,
[sync_row_hash] varbinary(32) NOT NULL,
[sync_is_deleted] bit NOT NULL,
[sync_created_at] datetime2(7) NOT NULL,
[sync_updated_at] datetime2(7) NOT NULL
);
END;
IF OBJECT_ID(N'ods.ele_sale_custom_order', N'U') IS NULL
BEGIN
CREATE TABLE [ods].[ele_sale_custom_order]
(
[id] int NOT NULL,
[campaign_id] int NULL,
[source_id] int NULL,
[medium_id] int NULL,
[company_id] int NOT NULL,
[partner_id] int NOT NULL,
[journal_id] int NULL,
[partner_invoice_id] int NOT NULL,
[partner_shipping_id] int NOT NULL,
[fiscal_position_id] int NULL,
[payment_term_id] int NULL,
[pricelist_id] int NULL,
[currency_id] int NULL,
[user_id] int NULL,
[team_id] int NULL,
[workflow_id] int NULL,
[current_sequence] int NULL,
[SlpCode] int NULL,
[GroupNum] int NULL,
[WhsCode] int NULL,
[Project] int NULL,
[marketing_campaign_id] int NULL,
[cntct_code] int NULL,
[ShipToCode] int NULL,
[CardCode2] int NULL,
[create_uid] int NULL,
[write_uid] int NULL,
[access_token] nvarchar(max) NULL,
[name] nvarchar(max) NOT NULL,
[state] nvarchar(max) NULL,
[client_order_ref] nvarchar(max) NULL,
[origin] nvarchar(max) NULL,
[reference] nvarchar(max) NULL,
[signed_by] nvarchar(max) NULL,
[invoice_status] nvarchar(max) NULL,
[VoucherTypeID] nvarchar(max) NULL,
[CardCode] nvarchar(max) NULL,
[TrnspCode] nvarchar(max) NULL,
[BPLId] nvarchar(max) NULL,
[Store] nvarchar(max) NULL,
[InvStore] nvarchar(max) NULL,
[BusinessArea] nvarchar(max) NULL,
[S1No] nvarchar(max) NULL,
[VoucherNo] nvarchar(max) NULL,
[StatusID] nvarchar(max) NULL,
[vat] nvarchar(max) NULL,
[EL_Construction_Code] nvarchar(max) NULL,
[EL_PowerGearlessCabinet] nvarchar(max) NULL,
[EL_PowerGearlessCabinet_Note] nvarchar(max) NULL,
[EL_QuantityStops] nvarchar(max) NULL,
[EL_Speed] nvarchar(max) NULL,
[EL_Speed_Note] nvarchar(max) NULL,
[EL_QuantityGroup] nvarchar(max) NULL,
[EL_QuantityGroup_Note] nvarchar(max) NULL,
[EL_TractorBrakeVoltage] nvarchar(max) NULL,
[EL_TractorBrakeVoltage_Note] nvarchar(max) NULL,
[EL_Encoder] nvarchar(max) NULL,
[EL_Trademark] nvarchar(max) NULL,
[report_type] nvarchar(max) NULL,
[validity_date] datetime2(6) NULL,
[PostingDate] date NULL,
[DocDueDate] date NULL,
[quote_date] date NULL,
[order_date] date NULL,
[expected_delivery_date] date NULL,
[actual_delivery_date] date NULL,
[note] nvarchar(max) NULL,
[NoteInternal] nvarchar(max) NULL,
[Comments] nvarchar(max) NULL,
[NoteForAct] nvarchar(max) NULL,
[currency_rate] decimal(38,10) NULL,
[amount_untaxed] decimal(38,10) NULL,
[amount_tax] decimal(38,10) NULL,
[amount_total] decimal(38,10) NULL,
[locked] bit NULL,
[require_signature] bit NULL,
[require_payment] bit NULL,
[promotion_is_applied] bit NULL,
[IsIssueInvoice] bit NULL,
[IsCOD] bit NULL,
[IsCOCQ] bit NULL,
[IsInstall] bit NULL,
[IsSetup] bit NULL,
[create_date] datetime2(6) NULL,
[commitment_date] datetime2(6) NULL,
[date_order] datetime2(6) NOT NULL,
[signed_on] datetime2(6) NULL,
[write_date] datetime2(6) NULL,
[prepayment_percent] float NULL,
[max_discount] float NULL,
[company_ref] nvarchar(max) NULL,
[trnsp_id] int NULL,
[blanket_agreement_id] int NULL,
[u_is_issue_invoice] nvarchar(max) NOT NULL,
[docnumber] nvarchar(max) NULL,
[credit_notice] nvarchar(max) NULL,
[sap_stt] int NULL,
[sap_u_sino] nvarchar(max) NULL,
[sap_opty_type] nvarchar(max) NULL,
[sap_voucher_no] nvarchar(max) NULL,
[sap_status_name] nvarchar(max) NULL,
[EL_Construction_Address] nvarchar(max) NULL,
[partner_ref] nvarchar(max) NULL,
[u_carcodecommission] int NULL,
[dispatch_notified_by] int NULL,
[so_create_result] nvarchar(max) NULL,
[so_create_lock_uuid] nvarchar(max) NULL,
[so_idem_key] nvarchar(max) NULL,
[dispatch_state] nvarchar(max) NULL,
[dispatch_webhook_key] nvarchar(max) NULL,
[dispatch_note] nvarchar(max) NULL,
[is_fully_stocked] bit NULL,
[so_create_attempted] bit NULL,
[has_commission_line] bit NULL,
[eta_datetime] datetime2(6) NULL,
[so_create_attempted_at] datetime2(6) NULL,
[dispatch_notified_at] datetime2(6) NULL,
[dispatch_send_count] int NULL,
[pay_last_remark] nvarchar(max) NULL,
[pay_updated_at] datetime2(6) NULL,
[pay_accumulated] float NULL,
[pay_last_amount] float NULL,
[sap_completed_at_hist] nvarchar(max) NULL,
[sap_completed_at] datetime2(6) NULL,
[credit_auto_pass] bit NULL,
[auto_be_promotion_log] nvarchar(max) NULL,
[auto_be_promotion_last_sync] datetime2(6) NULL,
[promotion_reason_id] int NULL,
[oms_eta_warning_message] nvarchar(max) NULL,
[oms_dispatch_eta_notified] bit NULL,
[oms_dispatch_upcoming_notified] bit NULL,
[oms_has_eta_adjustment] bit NULL,
[oms_eta_exceeds_delivery] bit NULL,
[oms_submitted_for_approval_at] datetime2(6) NULL,
[oms_credit_approved_at] datetime2(6) NULL,
[oms_max_eta_done] datetime2(6) NULL,
[oms_eta_sla_deadline] datetime2(6) NULL,
[oms_eta_sla_hours] float NULL,
[approval_rejected_step_name] nvarchar(max) NULL,
[oms_late_dispatch_alert_sent] bit NULL,
[oms_late_dispatch_alert_sent_at] datetime2(6) NULL,
[so_create_lock_at] datetime2(6) NULL,
[EL_Elevator_Code] nvarchar(max) NULL,
[sap_inv_no] nvarchar(max) NULL,
[sap_status_sync_error] nvarchar(max) NULL,
[sap_status_sync_at] datetime2(6) NULL,
[sync_source_id] int NOT NULL,
[sync_job_id] int NOT NULL,
[sync_run_id] bigint NOT NULL,
[sync_row_hash] varbinary(32) NOT NULL,
[sync_is_deleted] bit NOT NULL CONSTRAINT [DF_ele_sale_custom_order_IsDeleted] DEFAULT (0),
[sync_created_at] datetime2(7) NOT NULL,
[sync_updated_at] datetime2(7) NOT NULL,
CONSTRAINT [PK_ele_sale_custom_order] PRIMARY KEY ([sync_source_id], [id])
);
END;
IF OBJECT_ID(N'hist.J11_ele_sale_custom_order_History', N'U') IS NULL
BEGIN
CREATE TABLE [hist].[J11_ele_sale_custom_order_History]
(
[history_id] bigint IDENTITY(1,1) NOT NULL PRIMARY KEY,
[source_record_id] nvarchar(450) NOT NULL,
[id] int NULL,
[campaign_id] int NULL,
[source_id] int NULL,
[medium_id] int NULL,
[company_id] int NULL,
[partner_id] int NULL,
[journal_id] int NULL,
[partner_invoice_id] int NULL,
[partner_shipping_id] int NULL,
[fiscal_position_id] int NULL,
[payment_term_id] int NULL,
[pricelist_id] int NULL,
[currency_id] int NULL,
[user_id] int NULL,
[team_id] int NULL,
[workflow_id] int NULL,
[current_sequence] int NULL,
[SlpCode] int NULL,
[GroupNum] int NULL,
[WhsCode] int NULL,
[Project] int NULL,
[marketing_campaign_id] int NULL,
[cntct_code] int NULL,
[ShipToCode] int NULL,
[CardCode2] int NULL,
[create_uid] int NULL,
[write_uid] int NULL,
[access_token] nvarchar(max) NULL,
[name] nvarchar(max) NULL,
[state] nvarchar(max) NULL,
[client_order_ref] nvarchar(max) NULL,
[origin] nvarchar(max) NULL,
[reference] nvarchar(max) NULL,
[signed_by] nvarchar(max) NULL,
[invoice_status] nvarchar(max) NULL,
[VoucherTypeID] nvarchar(max) NULL,
[CardCode] nvarchar(max) NULL,
[TrnspCode] nvarchar(max) NULL,
[BPLId] nvarchar(max) NULL,
[Store] nvarchar(max) NULL,
[InvStore] nvarchar(max) NULL,
[BusinessArea] nvarchar(max) NULL,
[S1No] nvarchar(max) NULL,
[VoucherNo] nvarchar(max) NULL,
[StatusID] nvarchar(max) NULL,
[vat] nvarchar(max) NULL,
[EL_Construction_Code] nvarchar(max) NULL,
[EL_PowerGearlessCabinet] nvarchar(max) NULL,
[EL_PowerGearlessCabinet_Note] nvarchar(max) NULL,
[EL_QuantityStops] nvarchar(max) NULL,
[EL_Speed] nvarchar(max) NULL,
[EL_Speed_Note] nvarchar(max) NULL,
[EL_QuantityGroup] nvarchar(max) NULL,
[EL_QuantityGroup_Note] nvarchar(max) NULL,
[EL_TractorBrakeVoltage] nvarchar(max) NULL,
[EL_TractorBrakeVoltage_Note] nvarchar(max) NULL,
[EL_Encoder] nvarchar(max) NULL,
[EL_Trademark] nvarchar(max) NULL,
[report_type] nvarchar(max) NULL,
[validity_date] datetime2(6) NULL,
[PostingDate] date NULL,
[DocDueDate] date NULL,
[quote_date] date NULL,
[order_date] date NULL,
[expected_delivery_date] date NULL,
[actual_delivery_date] date NULL,
[note] nvarchar(max) NULL,
[NoteInternal] nvarchar(max) NULL,
[Comments] nvarchar(max) NULL,
[NoteForAct] nvarchar(max) NULL,
[currency_rate] decimal(38,10) NULL,
[amount_untaxed] decimal(38,10) NULL,
[amount_tax] decimal(38,10) NULL,
[amount_total] decimal(38,10) NULL,
[locked] bit NULL,
[require_signature] bit NULL,
[require_payment] bit NULL,
[promotion_is_applied] bit NULL,
[IsIssueInvoice] bit NULL,
[IsCOD] bit NULL,
[IsCOCQ] bit NULL,
[IsInstall] bit NULL,
[IsSetup] bit NULL,
[create_date] datetime2(6) NULL,
[commitment_date] datetime2(6) NULL,
[date_order] datetime2(6) NULL,
[signed_on] datetime2(6) NULL,
[write_date] datetime2(6) NULL,
[prepayment_percent] float NULL,
[max_discount] float NULL,
[company_ref] nvarchar(max) NULL,
[trnsp_id] int NULL,
[blanket_agreement_id] int NULL,
[u_is_issue_invoice] nvarchar(max) NULL,
[docnumber] nvarchar(max) NULL,
[credit_notice] nvarchar(max) NULL,
[sap_stt] int NULL,
[sap_u_sino] nvarchar(max) NULL,
[sap_opty_type] nvarchar(max) NULL,
[sap_voucher_no] nvarchar(max) NULL,
[sap_status_name] nvarchar(max) NULL,
[EL_Construction_Address] nvarchar(max) NULL,
[partner_ref] nvarchar(max) NULL,
[u_carcodecommission] int NULL,
[dispatch_notified_by] int NULL,
[so_create_result] nvarchar(max) NULL,
[so_create_lock_uuid] nvarchar(max) NULL,
[so_idem_key] nvarchar(max) NULL,
[dispatch_state] nvarchar(max) NULL,
[dispatch_webhook_key] nvarchar(max) NULL,
[dispatch_note] nvarchar(max) NULL,
[is_fully_stocked] bit NULL,
[so_create_attempted] bit NULL,
[has_commission_line] bit NULL,
[eta_datetime] datetime2(6) NULL,
[so_create_attempted_at] datetime2(6) NULL,
[dispatch_notified_at] datetime2(6) NULL,
[dispatch_send_count] int NULL,
[pay_last_remark] nvarchar(max) NULL,
[pay_updated_at] datetime2(6) NULL,
[pay_accumulated] float NULL,
[pay_last_amount] float NULL,
[sap_completed_at_hist] nvarchar(max) NULL,
[sap_completed_at] datetime2(6) NULL,
[credit_auto_pass] bit NULL,
[auto_be_promotion_log] nvarchar(max) NULL,
[auto_be_promotion_last_sync] datetime2(6) NULL,
[promotion_reason_id] int NULL,
[oms_eta_warning_message] nvarchar(max) NULL,
[oms_dispatch_eta_notified] bit NULL,
[oms_dispatch_upcoming_notified] bit NULL,
[oms_has_eta_adjustment] bit NULL,
[oms_eta_exceeds_delivery] bit NULL,
[oms_submitted_for_approval_at] datetime2(6) NULL,
[oms_credit_approved_at] datetime2(6) NULL,
[oms_max_eta_done] datetime2(6) NULL,
[oms_eta_sla_deadline] datetime2(6) NULL,
[oms_eta_sla_hours] float NULL,
[approval_rejected_step_name] nvarchar(max) NULL,
[oms_late_dispatch_alert_sent] bit NULL,
[oms_late_dispatch_alert_sent_at] datetime2(6) NULL,
[so_create_lock_at] datetime2(6) NULL,
[EL_Elevator_Code] nvarchar(max) NULL,
[sap_inv_no] nvarchar(max) NULL,
[sap_status_sync_error] nvarchar(max) NULL,
[sap_status_sync_at] datetime2(6) NULL,
[sync_source_id] int NOT NULL,
[sync_job_id] int NOT NULL,
[sync_run_id] bigint NOT NULL,
[valid_from] datetime2(7) NOT NULL,
[valid_to] datetime2(7) NULL,
[is_current] bit NOT NULL,
[row_hash] varbinary(32) NOT NULL,
[source_updated_at] datetimeoffset(7) NOT NULL,
[sync_is_deleted] bit NOT NULL
);
END;
IF COL_LENGTH(N'stg.J11_ele_sale_custom_order', N'id') IS NULL
BEGIN
ALTER TABLE [stg].[J11_ele_sale_custom_order] ADD [id] int NULL;
END;
IF COL_LENGTH(N'ods.ele_sale_custom_order', N'id') IS NULL
BEGIN
ALTER TABLE [ods].[ele_sale_custom_order] ADD [id] int NULL;
END;
IF COL_LENGTH(N'hist.J11_ele_sale_custom_order_History', N'id') IS NULL
BEGIN
ALTER TABLE [hist].[J11_ele_sale_custom_order_History] ADD [id] int NULL;
END;
IF COL_LENGTH(N'stg.J11_ele_sale_custom_order', N'campaign_id') IS NULL
BEGIN
ALTER TABLE [stg].[J11_ele_sale_custom_order] ADD [campaign_id] int NULL;
END;
IF COL_LENGTH(N'ods.ele_sale_custom_order', N'campaign_id') IS NULL
BEGIN
ALTER TABLE [ods].[ele_sale_custom_order] ADD [campaign_id] int NULL;
END;
IF COL_LENGTH(N'hist.J11_ele_sale_custom_order_History', N'campaign_id') IS NULL
BEGIN
ALTER TABLE [hist].[J11_ele_sale_custom_order_History] ADD [campaign_id] int NULL;
END;
IF COL_LENGTH(N'stg.J11_ele_sale_custom_order', N'source_id') IS NULL
BEGIN
ALTER TABLE [stg].[J11_ele_sale_custom_order] ADD [source_id] int NULL;
END;
IF COL_LENGTH(N'ods.ele_sale_custom_order', N'source_id') IS NULL
BEGIN
ALTER TABLE [ods].[ele_sale_custom_order] ADD [source_id] int NULL;
END;
IF COL_LENGTH(N'hist.J11_ele_sale_custom_order_History', N'source_id') IS NULL
BEGIN
ALTER TABLE [hist].[J11_ele_sale_custom_order_History] ADD [source_id] int NULL;
END;
IF COL_LENGTH(N'stg.J11_ele_sale_custom_order', N'medium_id') IS NULL
BEGIN
ALTER TABLE [stg].[J11_ele_sale_custom_order] ADD [medium_id] int NULL;
END;
IF COL_LENGTH(N'ods.ele_sale_custom_order', N'medium_id') IS NULL
BEGIN
ALTER TABLE [ods].[ele_sale_custom_order] ADD [medium_id] int NULL;
END;
IF COL_LENGTH(N'hist.J11_ele_sale_custom_order_History', N'medium_id') IS NULL
BEGIN
ALTER TABLE [hist].[J11_ele_sale_custom_order_History] ADD [medium_id] int NULL;
END;
IF COL_LENGTH(N'stg.J11_ele_sale_custom_order', N'company_id') IS NULL
BEGIN
ALTER TABLE [stg].[J11_ele_sale_custom_order] ADD [company_id] int NULL;
END;
IF COL_LENGTH(N'ods.ele_sale_custom_order', N'company_id') IS NULL
BEGIN
ALTER TABLE [ods].[ele_sale_custom_order] ADD [company_id] int NULL;
END;
IF COL_LENGTH(N'hist.J11_ele_sale_custom_order_History', N'company_id') IS NULL
BEGIN
ALTER TABLE [hist].[J11_ele_sale_custom_order_History] ADD [company_id] int NULL;
END;
IF COL_LENGTH(N'stg.J11_ele_sale_custom_order', N'partner_id') IS NULL
BEGIN
ALTER TABLE [stg].[J11_ele_sale_custom_order] ADD [partner_id] int NULL;
END;
IF COL_LENGTH(N'ods.ele_sale_custom_order', N'partner_id') IS NULL
BEGIN
ALTER TABLE [ods].[ele_sale_custom_order] ADD [partner_id] int NULL;
END;
IF COL_LENGTH(N'hist.J11_ele_sale_custom_order_History', N'partner_id') IS NULL
BEGIN
ALTER TABLE [hist].[J11_ele_sale_custom_order_History] ADD [partner_id] int NULL;
END;
IF COL_LENGTH(N'stg.J11_ele_sale_custom_order', N'journal_id') IS NULL
BEGIN
ALTER TABLE [stg].[J11_ele_sale_custom_order] ADD [journal_id] int NULL;
END;
IF COL_LENGTH(N'ods.ele_sale_custom_order', N'journal_id') IS NULL
BEGIN
ALTER TABLE [ods].[ele_sale_custom_order] ADD [journal_id] int NULL;
END;
IF COL_LENGTH(N'hist.J11_ele_sale_custom_order_History', N'journal_id') IS NULL
BEGIN
ALTER TABLE [hist].[J11_ele_sale_custom_order_History] ADD [journal_id] int NULL;
END;
IF COL_LENGTH(N'stg.J11_ele_sale_custom_order', N'partner_invoice_id') IS NULL
BEGIN
ALTER TABLE [stg].[J11_ele_sale_custom_order] ADD [partner_invoice_id] int NULL;
END;
IF COL_LENGTH(N'ods.ele_sale_custom_order', N'partner_invoice_id') IS NULL
BEGIN
ALTER TABLE [ods].[ele_sale_custom_order] ADD [partner_invoice_id] int NULL;
END;
IF COL_LENGTH(N'hist.J11_ele_sale_custom_order_History', N'partner_invoice_id') IS NULL
BEGIN
ALTER TABLE [hist].[J11_ele_sale_custom_order_History] ADD [partner_invoice_id] int NULL;
END;
IF COL_LENGTH(N'stg.J11_ele_sale_custom_order', N'partner_shipping_id') IS NULL
BEGIN
ALTER TABLE [stg].[J11_ele_sale_custom_order] ADD [partner_shipping_id] int NULL;
END;
IF COL_LENGTH(N'ods.ele_sale_custom_order', N'partner_shipping_id') IS NULL
BEGIN
ALTER TABLE [ods].[ele_sale_custom_order] ADD [partner_shipping_id] int NULL;
END;
IF COL_LENGTH(N'hist.J11_ele_sale_custom_order_History', N'partner_shipping_id') IS NULL
BEGIN
ALTER TABLE [hist].[J11_ele_sale_custom_order_History] ADD [partner_shipping_id] int NULL;
END;
IF COL_LENGTH(N'stg.J11_ele_sale_custom_order', N'fiscal_position_id') IS NULL
BEGIN
ALTER TABLE [stg].[J11_ele_sale_custom_order] ADD [fiscal_position_id] int NULL;
END;
IF COL_LENGTH(N'ods.ele_sale_custom_order', N'fiscal_position_id') IS NULL
BEGIN
ALTER TABLE [ods].[ele_sale_custom_order] ADD [fiscal_position_id] int NULL;
END;
IF COL_LENGTH(N'hist.J11_ele_sale_custom_order_History', N'fiscal_position_id') IS NULL
BEGIN
ALTER TABLE [hist].[J11_ele_sale_custom_order_History] ADD [fiscal_position_id] int NULL;
END;
IF COL_LENGTH(N'stg.J11_ele_sale_custom_order', N'payment_term_id') IS NULL
BEGIN
ALTER TABLE [stg].[J11_ele_sale_custom_order] ADD [payment_term_id] int NULL;
END;
IF COL_LENGTH(N'ods.ele_sale_custom_order', N'payment_term_id') IS NULL
BEGIN
ALTER TABLE [ods].[ele_sale_custom_order] ADD [payment_term_id] int NULL;
END;
IF COL_LENGTH(N'hist.J11_ele_sale_custom_order_History', N'payment_term_id') IS NULL
BEGIN
ALTER TABLE [hist].[J11_ele_sale_custom_order_History] ADD [payment_term_id] int NULL;
END;
IF COL_LENGTH(N'stg.J11_ele_sale_custom_order', N'pricelist_id') IS NULL
BEGIN
ALTER TABLE [stg].[J11_ele_sale_custom_order] ADD [pricelist_id] int NULL;
END;
IF COL_LENGTH(N'ods.ele_sale_custom_order', N'pricelist_id') IS NULL
BEGIN
ALTER TABLE [ods].[ele_sale_custom_order] ADD [pricelist_id] int NULL;
END;
IF COL_LENGTH(N'hist.J11_ele_sale_custom_order_History', N'pricelist_id') IS NULL
BEGIN
ALTER TABLE [hist].[J11_ele_sale_custom_order_History] ADD [pricelist_id] int NULL;
END;
IF COL_LENGTH(N'stg.J11_ele_sale_custom_order', N'currency_id') IS NULL
BEGIN
ALTER TABLE [stg].[J11_ele_sale_custom_order] ADD [currency_id] int NULL;
END;
IF COL_LENGTH(N'ods.ele_sale_custom_order', N'currency_id') IS NULL
BEGIN
ALTER TABLE [ods].[ele_sale_custom_order] ADD [currency_id] int NULL;
END;
IF COL_LENGTH(N'hist.J11_ele_sale_custom_order_History', N'currency_id') IS NULL
BEGIN
ALTER TABLE [hist].[J11_ele_sale_custom_order_History] ADD [currency_id] int NULL;
END;
IF COL_LENGTH(N'stg.J11_ele_sale_custom_order', N'user_id') IS NULL
BEGIN
ALTER TABLE [stg].[J11_ele_sale_custom_order] ADD [user_id] int NULL;
END;
IF COL_LENGTH(N'ods.ele_sale_custom_order', N'user_id') IS NULL
BEGIN
ALTER TABLE [ods].[ele_sale_custom_order] ADD [user_id] int NULL;
END;
IF COL_LENGTH(N'hist.J11_ele_sale_custom_order_History', N'user_id') IS NULL
BEGIN
ALTER TABLE [hist].[J11_ele_sale_custom_order_History] ADD [user_id] int NULL;
END;
IF COL_LENGTH(N'stg.J11_ele_sale_custom_order', N'team_id') IS NULL
BEGIN
ALTER TABLE [stg].[J11_ele_sale_custom_order] ADD [team_id] int NULL;
END;
IF COL_LENGTH(N'ods.ele_sale_custom_order', N'team_id') IS NULL
BEGIN
ALTER TABLE [ods].[ele_sale_custom_order] ADD [team_id] int NULL;
END;
IF COL_LENGTH(N'hist.J11_ele_sale_custom_order_History', N'team_id') IS NULL
BEGIN
ALTER TABLE [hist].[J11_ele_sale_custom_order_History] ADD [team_id] int NULL;
END;
IF COL_LENGTH(N'stg.J11_ele_sale_custom_order', N'workflow_id') IS NULL
BEGIN
ALTER TABLE [stg].[J11_ele_sale_custom_order] ADD [workflow_id] int NULL;
END;
IF COL_LENGTH(N'ods.ele_sale_custom_order', N'workflow_id') IS NULL
BEGIN
ALTER TABLE [ods].[ele_sale_custom_order] ADD [workflow_id] int NULL;
END;
IF COL_LENGTH(N'hist.J11_ele_sale_custom_order_History', N'workflow_id') IS NULL
BEGIN
ALTER TABLE [hist].[J11_ele_sale_custom_order_History] ADD [workflow_id] int NULL;
END;
IF COL_LENGTH(N'stg.J11_ele_sale_custom_order', N'current_sequence') IS NULL
BEGIN
ALTER TABLE [stg].[J11_ele_sale_custom_order] ADD [current_sequence] int NULL;
END;
IF COL_LENGTH(N'ods.ele_sale_custom_order', N'current_sequence') IS NULL
BEGIN
ALTER TABLE [ods].[ele_sale_custom_order] ADD [current_sequence] int NULL;
END;
IF COL_LENGTH(N'hist.J11_ele_sale_custom_order_History', N'current_sequence') IS NULL
BEGIN
ALTER TABLE [hist].[J11_ele_sale_custom_order_History] ADD [current_sequence] int NULL;
END;
IF COL_LENGTH(N'stg.J11_ele_sale_custom_order', N'SlpCode') IS NULL
BEGIN
ALTER TABLE [stg].[J11_ele_sale_custom_order] ADD [SlpCode] int NULL;
END;
IF COL_LENGTH(N'ods.ele_sale_custom_order', N'SlpCode') IS NULL
BEGIN
ALTER TABLE [ods].[ele_sale_custom_order] ADD [SlpCode] int NULL;
END;
IF COL_LENGTH(N'hist.J11_ele_sale_custom_order_History', N'SlpCode') IS NULL
BEGIN
ALTER TABLE [hist].[J11_ele_sale_custom_order_History] ADD [SlpCode] int NULL;
END;
IF COL_LENGTH(N'stg.J11_ele_sale_custom_order', N'GroupNum') IS NULL
BEGIN
ALTER TABLE [stg].[J11_ele_sale_custom_order] ADD [GroupNum] int NULL;
END;
IF COL_LENGTH(N'ods.ele_sale_custom_order', N'GroupNum') IS NULL
BEGIN
ALTER TABLE [ods].[ele_sale_custom_order] ADD [GroupNum] int NULL;
END;
IF COL_LENGTH(N'hist.J11_ele_sale_custom_order_History', N'GroupNum') IS NULL
BEGIN
ALTER TABLE [hist].[J11_ele_sale_custom_order_History] ADD [GroupNum] int NULL;
END;
IF COL_LENGTH(N'stg.J11_ele_sale_custom_order', N'WhsCode') IS NULL
BEGIN
ALTER TABLE [stg].[J11_ele_sale_custom_order] ADD [WhsCode] int NULL;
END;
IF COL_LENGTH(N'ods.ele_sale_custom_order', N'WhsCode') IS NULL
BEGIN
ALTER TABLE [ods].[ele_sale_custom_order] ADD [WhsCode] int NULL;
END;
IF COL_LENGTH(N'hist.J11_ele_sale_custom_order_History', N'WhsCode') IS NULL
BEGIN
ALTER TABLE [hist].[J11_ele_sale_custom_order_History] ADD [WhsCode] int NULL;
END;
IF COL_LENGTH(N'stg.J11_ele_sale_custom_order', N'Project') IS NULL
BEGIN
ALTER TABLE [stg].[J11_ele_sale_custom_order] ADD [Project] int NULL;
END;
IF COL_LENGTH(N'ods.ele_sale_custom_order', N'Project') IS NULL
BEGIN
ALTER TABLE [ods].[ele_sale_custom_order] ADD [Project] int NULL;
END;
IF COL_LENGTH(N'hist.J11_ele_sale_custom_order_History', N'Project') IS NULL
BEGIN
ALTER TABLE [hist].[J11_ele_sale_custom_order_History] ADD [Project] int NULL;
END;
IF COL_LENGTH(N'stg.J11_ele_sale_custom_order', N'marketing_campaign_id') IS NULL
BEGIN
ALTER TABLE [stg].[J11_ele_sale_custom_order] ADD [marketing_campaign_id] int NULL;
END;
IF COL_LENGTH(N'ods.ele_sale_custom_order', N'marketing_campaign_id') IS NULL
BEGIN
ALTER TABLE [ods].[ele_sale_custom_order] ADD [marketing_campaign_id] int NULL;
END;
IF COL_LENGTH(N'hist.J11_ele_sale_custom_order_History', N'marketing_campaign_id') IS NULL
BEGIN
ALTER TABLE [hist].[J11_ele_sale_custom_order_History] ADD [marketing_campaign_id] int NULL;
END;
IF COL_LENGTH(N'stg.J11_ele_sale_custom_order', N'cntct_code') IS NULL
BEGIN
ALTER TABLE [stg].[J11_ele_sale_custom_order] ADD [cntct_code] int NULL;
END;
IF COL_LENGTH(N'ods.ele_sale_custom_order', N'cntct_code') IS NULL
BEGIN
ALTER TABLE [ods].[ele_sale_custom_order] ADD [cntct_code] int NULL;
END;
IF COL_LENGTH(N'hist.J11_ele_sale_custom_order_History', N'cntct_code') IS NULL
BEGIN
ALTER TABLE [hist].[J11_ele_sale_custom_order_History] ADD [cntct_code] int NULL;
END;
IF COL_LENGTH(N'stg.J11_ele_sale_custom_order', N'ShipToCode') IS NULL
BEGIN
ALTER TABLE [stg].[J11_ele_sale_custom_order] ADD [ShipToCode] int NULL;
END;
IF COL_LENGTH(N'ods.ele_sale_custom_order', N'ShipToCode') IS NULL
BEGIN
ALTER TABLE [ods].[ele_sale_custom_order] ADD [ShipToCode] int NULL;
END;
IF COL_LENGTH(N'hist.J11_ele_sale_custom_order_History', N'ShipToCode') IS NULL
BEGIN
ALTER TABLE [hist].[J11_ele_sale_custom_order_History] ADD [ShipToCode] int NULL;
END;
IF COL_LENGTH(N'stg.J11_ele_sale_custom_order', N'CardCode2') IS NULL
BEGIN
ALTER TABLE [stg].[J11_ele_sale_custom_order] ADD [CardCode2] int NULL;
END;
IF COL_LENGTH(N'ods.ele_sale_custom_order', N'CardCode2') IS NULL
BEGIN
ALTER TABLE [ods].[ele_sale_custom_order] ADD [CardCode2] int NULL;
END;
IF COL_LENGTH(N'hist.J11_ele_sale_custom_order_History', N'CardCode2') IS NULL
BEGIN
ALTER TABLE [hist].[J11_ele_sale_custom_order_History] ADD [CardCode2] int NULL;
END;
IF COL_LENGTH(N'stg.J11_ele_sale_custom_order', N'create_uid') IS NULL
BEGIN
ALTER TABLE [stg].[J11_ele_sale_custom_order] ADD [create_uid] int NULL;
END;
IF COL_LENGTH(N'ods.ele_sale_custom_order', N'create_uid') IS NULL
BEGIN
ALTER TABLE [ods].[ele_sale_custom_order] ADD [create_uid] int NULL;
END;
IF COL_LENGTH(N'hist.J11_ele_sale_custom_order_History', N'create_uid') IS NULL
BEGIN
ALTER TABLE [hist].[J11_ele_sale_custom_order_History] ADD [create_uid] int NULL;
END;
IF COL_LENGTH(N'stg.J11_ele_sale_custom_order', N'write_uid') IS NULL
BEGIN
ALTER TABLE [stg].[J11_ele_sale_custom_order] ADD [write_uid] int NULL;
END;
IF COL_LENGTH(N'ods.ele_sale_custom_order', N'write_uid') IS NULL
BEGIN
ALTER TABLE [ods].[ele_sale_custom_order] ADD [write_uid] int NULL;
END;
IF COL_LENGTH(N'hist.J11_ele_sale_custom_order_History', N'write_uid') IS NULL
BEGIN
ALTER TABLE [hist].[J11_ele_sale_custom_order_History] ADD [write_uid] int NULL;
END;
IF COL_LENGTH(N'stg.J11_ele_sale_custom_order', N'access_token') IS NULL
BEGIN
ALTER TABLE [stg].[J11_ele_sale_custom_order] ADD [access_token] nvarchar(max) NULL;
END;
IF COL_LENGTH(N'ods.ele_sale_custom_order', N'access_token') IS NULL
BEGIN
ALTER TABLE [ods].[ele_sale_custom_order] ADD [access_token] nvarchar(max) NULL;
END;
IF COL_LENGTH(N'hist.J11_ele_sale_custom_order_History', N'access_token') IS NULL
BEGIN
ALTER TABLE [hist].[J11_ele_sale_custom_order_History] ADD [access_token] nvarchar(max) NULL;
END;
IF COL_LENGTH(N'stg.J11_ele_sale_custom_order', N'name') IS NULL
BEGIN
ALTER TABLE [stg].[J11_ele_sale_custom_order] ADD [name] nvarchar(max) NULL;
END;
IF COL_LENGTH(N'ods.ele_sale_custom_order', N'name') IS NULL
BEGIN
ALTER TABLE [ods].[ele_sale_custom_order] ADD [name] nvarchar(max) NULL;
END;
IF COL_LENGTH(N'hist.J11_ele_sale_custom_order_History', N'name') IS NULL
BEGIN
ALTER TABLE [hist].[J11_ele_sale_custom_order_History] ADD [name] nvarchar(max) NULL;
END;
IF COL_LENGTH(N'stg.J11_ele_sale_custom_order', N'state') IS NULL
BEGIN
ALTER TABLE [stg].[J11_ele_sale_custom_order] ADD [state] nvarchar(max) NULL;
END;
IF COL_LENGTH(N'ods.ele_sale_custom_order', N'state') IS NULL
BEGIN
ALTER TABLE [ods].[ele_sale_custom_order] ADD [state] nvarchar(max) NULL;
END;
IF COL_LENGTH(N'hist.J11_ele_sale_custom_order_History', N'state') IS NULL
BEGIN
ALTER TABLE [hist].[J11_ele_sale_custom_order_History] ADD [state] nvarchar(max) NULL;
END;
IF COL_LENGTH(N'stg.J11_ele_sale_custom_order', N'client_order_ref') IS NULL
BEGIN
ALTER TABLE [stg].[J11_ele_sale_custom_order] ADD [client_order_ref] nvarchar(max) NULL;
END;
IF COL_LENGTH(N'ods.ele_sale_custom_order', N'client_order_ref') IS NULL
BEGIN
ALTER TABLE [ods].[ele_sale_custom_order] ADD [client_order_ref] nvarchar(max) NULL;
END;
IF COL_LENGTH(N'hist.J11_ele_sale_custom_order_History', N'client_order_ref') IS NULL
BEGIN
ALTER TABLE [hist].[J11_ele_sale_custom_order_History] ADD [client_order_ref] nvarchar(max) NULL;
END;
IF COL_LENGTH(N'stg.J11_ele_sale_custom_order', N'origin') IS NULL
BEGIN
ALTER TABLE [stg].[J11_ele_sale_custom_order] ADD [origin] nvarchar(max) NULL;
END;
IF COL_LENGTH(N'ods.ele_sale_custom_order', N'origin') IS NULL
BEGIN
ALTER TABLE [ods].[ele_sale_custom_order] ADD [origin] nvarchar(max) NULL;
END;
IF COL_LENGTH(N'hist.J11_ele_sale_custom_order_History', N'origin') IS NULL
BEGIN
ALTER TABLE [hist].[J11_ele_sale_custom_order_History] ADD [origin] nvarchar(max) NULL;
END;
IF COL_LENGTH(N'stg.J11_ele_sale_custom_order', N'reference') IS NULL
BEGIN
ALTER TABLE [stg].[J11_ele_sale_custom_order] ADD [reference] nvarchar(max) NULL;
END;
IF COL_LENGTH(N'ods.ele_sale_custom_order', N'reference') IS NULL
BEGIN
ALTER TABLE [ods].[ele_sale_custom_order] ADD [reference] nvarchar(max) NULL;
END;
IF COL_LENGTH(N'hist.J11_ele_sale_custom_order_History', N'reference') IS NULL
BEGIN
ALTER TABLE [hist].[J11_ele_sale_custom_order_History] ADD [reference] nvarchar(max) NULL;
END;
IF COL_LENGTH(N'stg.J11_ele_sale_custom_order', N'signed_by') IS NULL
BEGIN
ALTER TABLE [stg].[J11_ele_sale_custom_order] ADD [signed_by] nvarchar(max) NULL;
END;
IF COL_LENGTH(N'ods.ele_sale_custom_order', N'signed_by') IS NULL
BEGIN
ALTER TABLE [ods].[ele_sale_custom_order] ADD [signed_by] nvarchar(max) NULL;
END;
IF COL_LENGTH(N'hist.J11_ele_sale_custom_order_History', N'signed_by') IS NULL
BEGIN
ALTER TABLE [hist].[J11_ele_sale_custom_order_History] ADD [signed_by] nvarchar(max) NULL;
END;
IF COL_LENGTH(N'stg.J11_ele_sale_custom_order', N'invoice_status') IS NULL
BEGIN
ALTER TABLE [stg].[J11_ele_sale_custom_order] ADD [invoice_status] nvarchar(max) NULL;
END;
IF COL_LENGTH(N'ods.ele_sale_custom_order', N'invoice_status') IS NULL
BEGIN
ALTER TABLE [ods].[ele_sale_custom_order] ADD [invoice_status] nvarchar(max) NULL;
END;
IF COL_LENGTH(N'hist.J11_ele_sale_custom_order_History', N'invoice_status') IS NULL
BEGIN
ALTER TABLE [hist].[J11_ele_sale_custom_order_History] ADD [invoice_status] nvarchar(max) NULL;
END;
IF COL_LENGTH(N'stg.J11_ele_sale_custom_order', N'VoucherTypeID') IS NULL
BEGIN
ALTER TABLE [stg].[J11_ele_sale_custom_order] ADD [VoucherTypeID] nvarchar(max) NULL;
END;
IF COL_LENGTH(N'ods.ele_sale_custom_order', N'VoucherTypeID') IS NULL
BEGIN
ALTER TABLE [ods].[ele_sale_custom_order] ADD [VoucherTypeID] nvarchar(max) NULL;
END;
IF COL_LENGTH(N'hist.J11_ele_sale_custom_order_History', N'VoucherTypeID') IS NULL
BEGIN
ALTER TABLE [hist].[J11_ele_sale_custom_order_History] ADD [VoucherTypeID] nvarchar(max) NULL;
END;
IF COL_LENGTH(N'stg.J11_ele_sale_custom_order', N'CardCode') IS NULL
BEGIN
ALTER TABLE [stg].[J11_ele_sale_custom_order] ADD [CardCode] nvarchar(max) NULL;
END;
IF COL_LENGTH(N'ods.ele_sale_custom_order', N'CardCode') IS NULL
BEGIN
ALTER TABLE [ods].[ele_sale_custom_order] ADD [CardCode] nvarchar(max) NULL;
END;
IF COL_LENGTH(N'hist.J11_ele_sale_custom_order_History', N'CardCode') IS NULL
BEGIN
ALTER TABLE [hist].[J11_ele_sale_custom_order_History] ADD [CardCode] nvarchar(max) NULL;
END;
IF COL_LENGTH(N'stg.J11_ele_sale_custom_order', N'TrnspCode') IS NULL
BEGIN
ALTER TABLE [stg].[J11_ele_sale_custom_order] ADD [TrnspCode] nvarchar(max) NULL;
END;
IF COL_LENGTH(N'ods.ele_sale_custom_order', N'TrnspCode') IS NULL
BEGIN
ALTER TABLE [ods].[ele_sale_custom_order] ADD [TrnspCode] nvarchar(max) NULL;
END;
IF COL_LENGTH(N'hist.J11_ele_sale_custom_order_History', N'TrnspCode') IS NULL
BEGIN
ALTER TABLE [hist].[J11_ele_sale_custom_order_History] ADD [TrnspCode] nvarchar(max) NULL;
END;
IF COL_LENGTH(N'stg.J11_ele_sale_custom_order', N'BPLId') IS NULL
BEGIN
ALTER TABLE [stg].[J11_ele_sale_custom_order] ADD [BPLId] nvarchar(max) NULL;
END;
IF COL_LENGTH(N'ods.ele_sale_custom_order', N'BPLId') IS NULL
BEGIN
ALTER TABLE [ods].[ele_sale_custom_order] ADD [BPLId] nvarchar(max) NULL;
END;
IF COL_LENGTH(N'hist.J11_ele_sale_custom_order_History', N'BPLId') IS NULL
BEGIN
ALTER TABLE [hist].[J11_ele_sale_custom_order_History] ADD [BPLId] nvarchar(max) NULL;
END;
IF COL_LENGTH(N'stg.J11_ele_sale_custom_order', N'Store') IS NULL
BEGIN
ALTER TABLE [stg].[J11_ele_sale_custom_order] ADD [Store] nvarchar(max) NULL;
END;
IF COL_LENGTH(N'ods.ele_sale_custom_order', N'Store') IS NULL
BEGIN
ALTER TABLE [ods].[ele_sale_custom_order] ADD [Store] nvarchar(max) NULL;
END;
IF COL_LENGTH(N'hist.J11_ele_sale_custom_order_History', N'Store') IS NULL
BEGIN
ALTER TABLE [hist].[J11_ele_sale_custom_order_History] ADD [Store] nvarchar(max) NULL;
END;
IF COL_LENGTH(N'stg.J11_ele_sale_custom_order', N'InvStore') IS NULL
BEGIN
ALTER TABLE [stg].[J11_ele_sale_custom_order] ADD [InvStore] nvarchar(max) NULL;
END;
IF COL_LENGTH(N'ods.ele_sale_custom_order', N'InvStore') IS NULL
BEGIN
ALTER TABLE [ods].[ele_sale_custom_order] ADD [InvStore] nvarchar(max) NULL;
END;
IF COL_LENGTH(N'hist.J11_ele_sale_custom_order_History', N'InvStore') IS NULL
BEGIN
ALTER TABLE [hist].[J11_ele_sale_custom_order_History] ADD [InvStore] nvarchar(max) NULL;
END;
IF COL_LENGTH(N'stg.J11_ele_sale_custom_order', N'BusinessArea') IS NULL
BEGIN
ALTER TABLE [stg].[J11_ele_sale_custom_order] ADD [BusinessArea] nvarchar(max) NULL;
END;
IF COL_LENGTH(N'ods.ele_sale_custom_order', N'BusinessArea') IS NULL
BEGIN
ALTER TABLE [ods].[ele_sale_custom_order] ADD [BusinessArea] nvarchar(max) NULL;
END;
IF COL_LENGTH(N'hist.J11_ele_sale_custom_order_History', N'BusinessArea') IS NULL
BEGIN
ALTER TABLE [hist].[J11_ele_sale_custom_order_History] ADD [BusinessArea] nvarchar(max) NULL;
END;
IF COL_LENGTH(N'stg.J11_ele_sale_custom_order', N'S1No') IS NULL
BEGIN
ALTER TABLE [stg].[J11_ele_sale_custom_order] ADD [S1No] nvarchar(max) NULL;
END;
IF COL_LENGTH(N'ods.ele_sale_custom_order', N'S1No') IS NULL
BEGIN
ALTER TABLE [ods].[ele_sale_custom_order] ADD [S1No] nvarchar(max) NULL;
END;
IF COL_LENGTH(N'hist.J11_ele_sale_custom_order_History', N'S1No') IS NULL
BEGIN
ALTER TABLE [hist].[J11_ele_sale_custom_order_History] ADD [S1No] nvarchar(max) NULL;
END;
IF COL_LENGTH(N'stg.J11_ele_sale_custom_order', N'VoucherNo') IS NULL
BEGIN
ALTER TABLE [stg].[J11_ele_sale_custom_order] ADD [VoucherNo] nvarchar(max) NULL;
END;
IF COL_LENGTH(N'ods.ele_sale_custom_order', N'VoucherNo') IS NULL
BEGIN
ALTER TABLE [ods].[ele_sale_custom_order] ADD [VoucherNo] nvarchar(max) NULL;
END;
IF COL_LENGTH(N'hist.J11_ele_sale_custom_order_History', N'VoucherNo') IS NULL
BEGIN
ALTER TABLE [hist].[J11_ele_sale_custom_order_History] ADD [VoucherNo] nvarchar(max) NULL;
END;
IF COL_LENGTH(N'stg.J11_ele_sale_custom_order', N'StatusID') IS NULL
BEGIN
ALTER TABLE [stg].[J11_ele_sale_custom_order] ADD [StatusID] nvarchar(max) NULL;
END;
IF COL_LENGTH(N'ods.ele_sale_custom_order', N'StatusID') IS NULL
BEGIN
ALTER TABLE [ods].[ele_sale_custom_order] ADD [StatusID] nvarchar(max) NULL;
END;
IF COL_LENGTH(N'hist.J11_ele_sale_custom_order_History', N'StatusID') IS NULL
BEGIN
ALTER TABLE [hist].[J11_ele_sale_custom_order_History] ADD [StatusID] nvarchar(max) NULL;
END;
IF COL_LENGTH(N'stg.J11_ele_sale_custom_order', N'vat') IS NULL
BEGIN
ALTER TABLE [stg].[J11_ele_sale_custom_order] ADD [vat] nvarchar(max) NULL;
END;
IF COL_LENGTH(N'ods.ele_sale_custom_order', N'vat') IS NULL
BEGIN
ALTER TABLE [ods].[ele_sale_custom_order] ADD [vat] nvarchar(max) NULL;
END;
IF COL_LENGTH(N'hist.J11_ele_sale_custom_order_History', N'vat') IS NULL
BEGIN
ALTER TABLE [hist].[J11_ele_sale_custom_order_History] ADD [vat] nvarchar(max) NULL;
END;
IF COL_LENGTH(N'stg.J11_ele_sale_custom_order', N'EL_Construction_Code') IS NULL
BEGIN
ALTER TABLE [stg].[J11_ele_sale_custom_order] ADD [EL_Construction_Code] nvarchar(max) NULL;
END;
IF COL_LENGTH(N'ods.ele_sale_custom_order', N'EL_Construction_Code') IS NULL
BEGIN
ALTER TABLE [ods].[ele_sale_custom_order] ADD [EL_Construction_Code] nvarchar(max) NULL;
END;
IF COL_LENGTH(N'hist.J11_ele_sale_custom_order_History', N'EL_Construction_Code') IS NULL
BEGIN
ALTER TABLE [hist].[J11_ele_sale_custom_order_History] ADD [EL_Construction_Code] nvarchar(max) NULL;
END;
IF COL_LENGTH(N'stg.J11_ele_sale_custom_order', N'EL_PowerGearlessCabinet') IS NULL
BEGIN
ALTER TABLE [stg].[J11_ele_sale_custom_order] ADD [EL_PowerGearlessCabinet] nvarchar(max) NULL;
END;
IF COL_LENGTH(N'ods.ele_sale_custom_order', N'EL_PowerGearlessCabinet') IS NULL
BEGIN
ALTER TABLE [ods].[ele_sale_custom_order] ADD [EL_PowerGearlessCabinet] nvarchar(max) NULL;
END;
IF COL_LENGTH(N'hist.J11_ele_sale_custom_order_History', N'EL_PowerGearlessCabinet') IS NULL
BEGIN
ALTER TABLE [hist].[J11_ele_sale_custom_order_History] ADD [EL_PowerGearlessCabinet] nvarchar(max) NULL;
END;
IF COL_LENGTH(N'stg.J11_ele_sale_custom_order', N'EL_PowerGearlessCabinet_Note') IS NULL
BEGIN
ALTER TABLE [stg].[J11_ele_sale_custom_order] ADD [EL_PowerGearlessCabinet_Note] nvarchar(max) NULL;
END;
IF COL_LENGTH(N'ods.ele_sale_custom_order', N'EL_PowerGearlessCabinet_Note') IS NULL
BEGIN
ALTER TABLE [ods].[ele_sale_custom_order] ADD [EL_PowerGearlessCabinet_Note] nvarchar(max) NULL;
END;
IF COL_LENGTH(N'hist.J11_ele_sale_custom_order_History', N'EL_PowerGearlessCabinet_Note') IS NULL
BEGIN
ALTER TABLE [hist].[J11_ele_sale_custom_order_History] ADD [EL_PowerGearlessCabinet_Note] nvarchar(max) NULL;
END;
IF COL_LENGTH(N'stg.J11_ele_sale_custom_order', N'EL_QuantityStops') IS NULL
BEGIN
ALTER TABLE [stg].[J11_ele_sale_custom_order] ADD [EL_QuantityStops] nvarchar(max) NULL;
END;
IF COL_LENGTH(N'ods.ele_sale_custom_order', N'EL_QuantityStops') IS NULL
BEGIN
ALTER TABLE [ods].[ele_sale_custom_order] ADD [EL_QuantityStops] nvarchar(max) NULL;
END;
IF COL_LENGTH(N'hist.J11_ele_sale_custom_order_History', N'EL_QuantityStops') IS NULL
BEGIN
ALTER TABLE [hist].[J11_ele_sale_custom_order_History] ADD [EL_QuantityStops] nvarchar(max) NULL;
END;
IF COL_LENGTH(N'stg.J11_ele_sale_custom_order', N'EL_Speed') IS NULL
BEGIN
ALTER TABLE [stg].[J11_ele_sale_custom_order] ADD [EL_Speed] nvarchar(max) NULL;
END;
IF COL_LENGTH(N'ods.ele_sale_custom_order', N'EL_Speed') IS NULL
BEGIN
ALTER TABLE [ods].[ele_sale_custom_order] ADD [EL_Speed] nvarchar(max) NULL;
END;
IF COL_LENGTH(N'hist.J11_ele_sale_custom_order_History', N'EL_Speed') IS NULL
BEGIN
ALTER TABLE [hist].[J11_ele_sale_custom_order_History] ADD [EL_Speed] nvarchar(max) NULL;
END;
IF COL_LENGTH(N'stg.J11_ele_sale_custom_order', N'EL_Speed_Note') IS NULL
BEGIN
ALTER TABLE [stg].[J11_ele_sale_custom_order] ADD [EL_Speed_Note] nvarchar(max) NULL;
END;
IF COL_LENGTH(N'ods.ele_sale_custom_order', N'EL_Speed_Note') IS NULL
BEGIN
ALTER TABLE [ods].[ele_sale_custom_order] ADD [EL_Speed_Note] nvarchar(max) NULL;
END;
IF COL_LENGTH(N'hist.J11_ele_sale_custom_order_History', N'EL_Speed_Note') IS NULL
BEGIN
ALTER TABLE [hist].[J11_ele_sale_custom_order_History] ADD [EL_Speed_Note] nvarchar(max) NULL;
END;
IF COL_LENGTH(N'stg.J11_ele_sale_custom_order', N'EL_QuantityGroup') IS NULL
BEGIN
ALTER TABLE [stg].[J11_ele_sale_custom_order] ADD [EL_QuantityGroup] nvarchar(max) NULL;
END;
IF COL_LENGTH(N'ods.ele_sale_custom_order', N'EL_QuantityGroup') IS NULL
BEGIN
ALTER TABLE [ods].[ele_sale_custom_order] ADD [EL_QuantityGroup] nvarchar(max) NULL;
END;
IF COL_LENGTH(N'hist.J11_ele_sale_custom_order_History', N'EL_QuantityGroup') IS NULL
BEGIN
ALTER TABLE [hist].[J11_ele_sale_custom_order_History] ADD [EL_QuantityGroup] nvarchar(max) NULL;
END;
IF COL_LENGTH(N'stg.J11_ele_sale_custom_order', N'EL_QuantityGroup_Note') IS NULL
BEGIN
ALTER TABLE [stg].[J11_ele_sale_custom_order] ADD [EL_QuantityGroup_Note] nvarchar(max) NULL;
END;
IF COL_LENGTH(N'ods.ele_sale_custom_order', N'EL_QuantityGroup_Note') IS NULL
BEGIN
ALTER TABLE [ods].[ele_sale_custom_order] ADD [EL_QuantityGroup_Note] nvarchar(max) NULL;
END;
IF COL_LENGTH(N'hist.J11_ele_sale_custom_order_History', N'EL_QuantityGroup_Note') IS NULL
BEGIN
ALTER TABLE [hist].[J11_ele_sale_custom_order_History] ADD [EL_QuantityGroup_Note] nvarchar(max) NULL;
END;
IF COL_LENGTH(N'stg.J11_ele_sale_custom_order', N'EL_TractorBrakeVoltage') IS NULL
BEGIN
ALTER TABLE [stg].[J11_ele_sale_custom_order] ADD [EL_TractorBrakeVoltage] nvarchar(max) NULL;
END;
IF COL_LENGTH(N'ods.ele_sale_custom_order', N'EL_TractorBrakeVoltage') IS NULL
BEGIN
ALTER TABLE [ods].[ele_sale_custom_order] ADD [EL_TractorBrakeVoltage] nvarchar(max) NULL;
END;
IF COL_LENGTH(N'hist.J11_ele_sale_custom_order_History', N'EL_TractorBrakeVoltage') IS NULL
BEGIN
ALTER TABLE [hist].[J11_ele_sale_custom_order_History] ADD [EL_TractorBrakeVoltage] nvarchar(max) NULL;
END;
IF COL_LENGTH(N'stg.J11_ele_sale_custom_order', N'EL_TractorBrakeVoltage_Note') IS NULL
BEGIN
ALTER TABLE [stg].[J11_ele_sale_custom_order] ADD [EL_TractorBrakeVoltage_Note] nvarchar(max) NULL;
END;
IF COL_LENGTH(N'ods.ele_sale_custom_order', N'EL_TractorBrakeVoltage_Note') IS NULL
BEGIN
ALTER TABLE [ods].[ele_sale_custom_order] ADD [EL_TractorBrakeVoltage_Note] nvarchar(max) NULL;
END;
IF COL_LENGTH(N'hist.J11_ele_sale_custom_order_History', N'EL_TractorBrakeVoltage_Note') IS NULL
BEGIN
ALTER TABLE [hist].[J11_ele_sale_custom_order_History] ADD [EL_TractorBrakeVoltage_Note] nvarchar(max) NULL;
END;
IF COL_LENGTH(N'stg.J11_ele_sale_custom_order', N'EL_Encoder') IS NULL
BEGIN
ALTER TABLE [stg].[J11_ele_sale_custom_order] ADD [EL_Encoder] nvarchar(max) NULL;
END;
IF COL_LENGTH(N'ods.ele_sale_custom_order', N'EL_Encoder') IS NULL
BEGIN
ALTER TABLE [ods].[ele_sale_custom_order] ADD [EL_Encoder] nvarchar(max) NULL;
END;
IF COL_LENGTH(N'hist.J11_ele_sale_custom_order_History', N'EL_Encoder') IS NULL
BEGIN
ALTER TABLE [hist].[J11_ele_sale_custom_order_History] ADD [EL_Encoder] nvarchar(max) NULL;
END;
IF COL_LENGTH(N'stg.J11_ele_sale_custom_order', N'EL_Trademark') IS NULL
BEGIN
ALTER TABLE [stg].[J11_ele_sale_custom_order] ADD [EL_Trademark] nvarchar(max) NULL;
END;
IF COL_LENGTH(N'ods.ele_sale_custom_order', N'EL_Trademark') IS NULL
BEGIN
ALTER TABLE [ods].[ele_sale_custom_order] ADD [EL_Trademark] nvarchar(max) NULL;
END;
IF COL_LENGTH(N'hist.J11_ele_sale_custom_order_History', N'EL_Trademark') IS NULL
BEGIN
ALTER TABLE [hist].[J11_ele_sale_custom_order_History] ADD [EL_Trademark] nvarchar(max) NULL;
END;
IF COL_LENGTH(N'stg.J11_ele_sale_custom_order', N'report_type') IS NULL
BEGIN
ALTER TABLE [stg].[J11_ele_sale_custom_order] ADD [report_type] nvarchar(max) NULL;
END;
IF COL_LENGTH(N'ods.ele_sale_custom_order', N'report_type') IS NULL
BEGIN
ALTER TABLE [ods].[ele_sale_custom_order] ADD [report_type] nvarchar(max) NULL;
END;
IF COL_LENGTH(N'hist.J11_ele_sale_custom_order_History', N'report_type') IS NULL
BEGIN
ALTER TABLE [hist].[J11_ele_sale_custom_order_History] ADD [report_type] nvarchar(max) NULL;
END;
IF COL_LENGTH(N'stg.J11_ele_sale_custom_order', N'validity_date') IS NULL
BEGIN
ALTER TABLE [stg].[J11_ele_sale_custom_order] ADD [validity_date] datetime2(6) NULL;
END;
IF COL_LENGTH(N'ods.ele_sale_custom_order', N'validity_date') IS NULL
BEGIN
ALTER TABLE [ods].[ele_sale_custom_order] ADD [validity_date] datetime2(6) NULL;
END;
IF COL_LENGTH(N'hist.J11_ele_sale_custom_order_History', N'validity_date') IS NULL
BEGIN
ALTER TABLE [hist].[J11_ele_sale_custom_order_History] ADD [validity_date] datetime2(6) NULL;
END;
IF COL_LENGTH(N'stg.J11_ele_sale_custom_order', N'PostingDate') IS NULL
BEGIN
ALTER TABLE [stg].[J11_ele_sale_custom_order] ADD [PostingDate] date NULL;
END;
IF COL_LENGTH(N'ods.ele_sale_custom_order', N'PostingDate') IS NULL
BEGIN
ALTER TABLE [ods].[ele_sale_custom_order] ADD [PostingDate] date NULL;
END;
IF COL_LENGTH(N'hist.J11_ele_sale_custom_order_History', N'PostingDate') IS NULL
BEGIN
ALTER TABLE [hist].[J11_ele_sale_custom_order_History] ADD [PostingDate] date NULL;
END;
IF COL_LENGTH(N'stg.J11_ele_sale_custom_order', N'DocDueDate') IS NULL
BEGIN
ALTER TABLE [stg].[J11_ele_sale_custom_order] ADD [DocDueDate] date NULL;
END;
IF COL_LENGTH(N'ods.ele_sale_custom_order', N'DocDueDate') IS NULL
BEGIN
ALTER TABLE [ods].[ele_sale_custom_order] ADD [DocDueDate] date NULL;
END;
IF COL_LENGTH(N'hist.J11_ele_sale_custom_order_History', N'DocDueDate') IS NULL
BEGIN
ALTER TABLE [hist].[J11_ele_sale_custom_order_History] ADD [DocDueDate] date NULL;
END;
IF COL_LENGTH(N'stg.J11_ele_sale_custom_order', N'quote_date') IS NULL
BEGIN
ALTER TABLE [stg].[J11_ele_sale_custom_order] ADD [quote_date] date NULL;
END;
IF COL_LENGTH(N'ods.ele_sale_custom_order', N'quote_date') IS NULL
BEGIN
ALTER TABLE [ods].[ele_sale_custom_order] ADD [quote_date] date NULL;
END;
IF COL_LENGTH(N'hist.J11_ele_sale_custom_order_History', N'quote_date') IS NULL
BEGIN
ALTER TABLE [hist].[J11_ele_sale_custom_order_History] ADD [quote_date] date NULL;
END;
IF COL_LENGTH(N'stg.J11_ele_sale_custom_order', N'order_date') IS NULL
BEGIN
ALTER TABLE [stg].[J11_ele_sale_custom_order] ADD [order_date] date NULL;
END;
IF COL_LENGTH(N'ods.ele_sale_custom_order', N'order_date') IS NULL
BEGIN
ALTER TABLE [ods].[ele_sale_custom_order] ADD [order_date] date NULL;
END;
IF COL_LENGTH(N'hist.J11_ele_sale_custom_order_History', N'order_date') IS NULL
BEGIN
ALTER TABLE [hist].[J11_ele_sale_custom_order_History] ADD [order_date] date NULL;
END;
IF COL_LENGTH(N'stg.J11_ele_sale_custom_order', N'expected_delivery_date') IS NULL
BEGIN
ALTER TABLE [stg].[J11_ele_sale_custom_order] ADD [expected_delivery_date] date NULL;
END;
IF COL_LENGTH(N'ods.ele_sale_custom_order', N'expected_delivery_date') IS NULL
BEGIN
ALTER TABLE [ods].[ele_sale_custom_order] ADD [expected_delivery_date] date NULL;
END;
IF COL_LENGTH(N'hist.J11_ele_sale_custom_order_History', N'expected_delivery_date') IS NULL
BEGIN
ALTER TABLE [hist].[J11_ele_sale_custom_order_History] ADD [expected_delivery_date] date NULL;
END;
IF COL_LENGTH(N'stg.J11_ele_sale_custom_order', N'actual_delivery_date') IS NULL
BEGIN
ALTER TABLE [stg].[J11_ele_sale_custom_order] ADD [actual_delivery_date] date NULL;
END;
IF COL_LENGTH(N'ods.ele_sale_custom_order', N'actual_delivery_date') IS NULL
BEGIN
ALTER TABLE [ods].[ele_sale_custom_order] ADD [actual_delivery_date] date NULL;
END;
IF COL_LENGTH(N'hist.J11_ele_sale_custom_order_History', N'actual_delivery_date') IS NULL
BEGIN
ALTER TABLE [hist].[J11_ele_sale_custom_order_History] ADD [actual_delivery_date] date NULL;
END;
IF COL_LENGTH(N'stg.J11_ele_sale_custom_order', N'note') IS NULL
BEGIN
ALTER TABLE [stg].[J11_ele_sale_custom_order] ADD [note] nvarchar(max) NULL;
END;
IF COL_LENGTH(N'ods.ele_sale_custom_order', N'note') IS NULL
BEGIN
ALTER TABLE [ods].[ele_sale_custom_order] ADD [note] nvarchar(max) NULL;
END;
IF COL_LENGTH(N'hist.J11_ele_sale_custom_order_History', N'note') IS NULL
BEGIN
ALTER TABLE [hist].[J11_ele_sale_custom_order_History] ADD [note] nvarchar(max) NULL;
END;
IF COL_LENGTH(N'stg.J11_ele_sale_custom_order', N'NoteInternal') IS NULL
BEGIN
ALTER TABLE [stg].[J11_ele_sale_custom_order] ADD [NoteInternal] nvarchar(max) NULL;
END;
IF COL_LENGTH(N'ods.ele_sale_custom_order', N'NoteInternal') IS NULL
BEGIN
ALTER TABLE [ods].[ele_sale_custom_order] ADD [NoteInternal] nvarchar(max) NULL;
END;
IF COL_LENGTH(N'hist.J11_ele_sale_custom_order_History', N'NoteInternal') IS NULL
BEGIN
ALTER TABLE [hist].[J11_ele_sale_custom_order_History] ADD [NoteInternal] nvarchar(max) NULL;
END;
IF COL_LENGTH(N'stg.J11_ele_sale_custom_order', N'Comments') IS NULL
BEGIN
ALTER TABLE [stg].[J11_ele_sale_custom_order] ADD [Comments] nvarchar(max) NULL;
END;
IF COL_LENGTH(N'ods.ele_sale_custom_order', N'Comments') IS NULL
BEGIN
ALTER TABLE [ods].[ele_sale_custom_order] ADD [Comments] nvarchar(max) NULL;
END;
IF COL_LENGTH(N'hist.J11_ele_sale_custom_order_History', N'Comments') IS NULL
BEGIN
ALTER TABLE [hist].[J11_ele_sale_custom_order_History] ADD [Comments] nvarchar(max) NULL;
END;
IF COL_LENGTH(N'stg.J11_ele_sale_custom_order', N'NoteForAct') IS NULL
BEGIN
ALTER TABLE [stg].[J11_ele_sale_custom_order] ADD [NoteForAct] nvarchar(max) NULL;
END;
IF COL_LENGTH(N'ods.ele_sale_custom_order', N'NoteForAct') IS NULL
BEGIN
ALTER TABLE [ods].[ele_sale_custom_order] ADD [NoteForAct] nvarchar(max) NULL;
END;
IF COL_LENGTH(N'hist.J11_ele_sale_custom_order_History', N'NoteForAct') IS NULL
BEGIN
ALTER TABLE [hist].[J11_ele_sale_custom_order_History] ADD [NoteForAct] nvarchar(max) NULL;
END;
IF COL_LENGTH(N'stg.J11_ele_sale_custom_order', N'currency_rate') IS NULL
BEGIN
ALTER TABLE [stg].[J11_ele_sale_custom_order] ADD [currency_rate] decimal(38,10) NULL;
END;
IF COL_LENGTH(N'ods.ele_sale_custom_order', N'currency_rate') IS NULL
BEGIN
ALTER TABLE [ods].[ele_sale_custom_order] ADD [currency_rate] decimal(38,10) NULL;
END;
IF COL_LENGTH(N'hist.J11_ele_sale_custom_order_History', N'currency_rate') IS NULL
BEGIN
ALTER TABLE [hist].[J11_ele_sale_custom_order_History] ADD [currency_rate] decimal(38,10) NULL;
END;
IF COL_LENGTH(N'stg.J11_ele_sale_custom_order', N'amount_untaxed') IS NULL
BEGIN
ALTER TABLE [stg].[J11_ele_sale_custom_order] ADD [amount_untaxed] decimal(38,10) NULL;
END;
IF COL_LENGTH(N'ods.ele_sale_custom_order', N'amount_untaxed') IS NULL
BEGIN
ALTER TABLE [ods].[ele_sale_custom_order] ADD [amount_untaxed] decimal(38,10) NULL;
END;
IF COL_LENGTH(N'hist.J11_ele_sale_custom_order_History', N'amount_untaxed') IS NULL
BEGIN
ALTER TABLE [hist].[J11_ele_sale_custom_order_History] ADD [amount_untaxed] decimal(38,10) NULL;
END;
IF COL_LENGTH(N'stg.J11_ele_sale_custom_order', N'amount_tax') IS NULL
BEGIN
ALTER TABLE [stg].[J11_ele_sale_custom_order] ADD [amount_tax] decimal(38,10) NULL;
END;
IF COL_LENGTH(N'ods.ele_sale_custom_order', N'amount_tax') IS NULL
BEGIN
ALTER TABLE [ods].[ele_sale_custom_order] ADD [amount_tax] decimal(38,10) NULL;
END;
IF COL_LENGTH(N'hist.J11_ele_sale_custom_order_History', N'amount_tax') IS NULL
BEGIN
ALTER TABLE [hist].[J11_ele_sale_custom_order_History] ADD [amount_tax] decimal(38,10) NULL;
END;
IF COL_LENGTH(N'stg.J11_ele_sale_custom_order', N'amount_total') IS NULL
BEGIN
ALTER TABLE [stg].[J11_ele_sale_custom_order] ADD [amount_total] decimal(38,10) NULL;
END;
IF COL_LENGTH(N'ods.ele_sale_custom_order', N'amount_total') IS NULL
BEGIN
ALTER TABLE [ods].[ele_sale_custom_order] ADD [amount_total] decimal(38,10) NULL;
END;
IF COL_LENGTH(N'hist.J11_ele_sale_custom_order_History', N'amount_total') IS NULL
BEGIN
ALTER TABLE [hist].[J11_ele_sale_custom_order_History] ADD [amount_total] decimal(38,10) NULL;
END;
IF COL_LENGTH(N'stg.J11_ele_sale_custom_order', N'locked') IS NULL
BEGIN
ALTER TABLE [stg].[J11_ele_sale_custom_order] ADD [locked] bit NULL;
END;
IF COL_LENGTH(N'ods.ele_sale_custom_order', N'locked') IS NULL
BEGIN
ALTER TABLE [ods].[ele_sale_custom_order] ADD [locked] bit NULL;
END;
IF COL_LENGTH(N'hist.J11_ele_sale_custom_order_History', N'locked') IS NULL
BEGIN
ALTER TABLE [hist].[J11_ele_sale_custom_order_History] ADD [locked] bit NULL;
END;
IF COL_LENGTH(N'stg.J11_ele_sale_custom_order', N'require_signature') IS NULL
BEGIN
ALTER TABLE [stg].[J11_ele_sale_custom_order] ADD [require_signature] bit NULL;
END;
IF COL_LENGTH(N'ods.ele_sale_custom_order', N'require_signature') IS NULL
BEGIN
ALTER TABLE [ods].[ele_sale_custom_order] ADD [require_signature] bit NULL;
END;
IF COL_LENGTH(N'hist.J11_ele_sale_custom_order_History', N'require_signature') IS NULL
BEGIN
ALTER TABLE [hist].[J11_ele_sale_custom_order_History] ADD [require_signature] bit NULL;
END;
IF COL_LENGTH(N'stg.J11_ele_sale_custom_order', N'require_payment') IS NULL
BEGIN
ALTER TABLE [stg].[J11_ele_sale_custom_order] ADD [require_payment] bit NULL;
END;
IF COL_LENGTH(N'ods.ele_sale_custom_order', N'require_payment') IS NULL
BEGIN
ALTER TABLE [ods].[ele_sale_custom_order] ADD [require_payment] bit NULL;
END;
IF COL_LENGTH(N'hist.J11_ele_sale_custom_order_History', N'require_payment') IS NULL
BEGIN
ALTER TABLE [hist].[J11_ele_sale_custom_order_History] ADD [require_payment] bit NULL;
END;
IF COL_LENGTH(N'stg.J11_ele_sale_custom_order', N'promotion_is_applied') IS NULL
BEGIN
ALTER TABLE [stg].[J11_ele_sale_custom_order] ADD [promotion_is_applied] bit NULL;
END;
IF COL_LENGTH(N'ods.ele_sale_custom_order', N'promotion_is_applied') IS NULL
BEGIN
ALTER TABLE [ods].[ele_sale_custom_order] ADD [promotion_is_applied] bit NULL;
END;
IF COL_LENGTH(N'hist.J11_ele_sale_custom_order_History', N'promotion_is_applied') IS NULL
BEGIN
ALTER TABLE [hist].[J11_ele_sale_custom_order_History] ADD [promotion_is_applied] bit NULL;
END;
IF COL_LENGTH(N'stg.J11_ele_sale_custom_order', N'IsIssueInvoice') IS NULL
BEGIN
ALTER TABLE [stg].[J11_ele_sale_custom_order] ADD [IsIssueInvoice] bit NULL;
END;
IF COL_LENGTH(N'ods.ele_sale_custom_order', N'IsIssueInvoice') IS NULL
BEGIN
ALTER TABLE [ods].[ele_sale_custom_order] ADD [IsIssueInvoice] bit NULL;
END;
IF COL_LENGTH(N'hist.J11_ele_sale_custom_order_History', N'IsIssueInvoice') IS NULL
BEGIN
ALTER TABLE [hist].[J11_ele_sale_custom_order_History] ADD [IsIssueInvoice] bit NULL;
END;
IF COL_LENGTH(N'stg.J11_ele_sale_custom_order', N'IsCOD') IS NULL
BEGIN
ALTER TABLE [stg].[J11_ele_sale_custom_order] ADD [IsCOD] bit NULL;
END;
IF COL_LENGTH(N'ods.ele_sale_custom_order', N'IsCOD') IS NULL
BEGIN
ALTER TABLE [ods].[ele_sale_custom_order] ADD [IsCOD] bit NULL;
END;
IF COL_LENGTH(N'hist.J11_ele_sale_custom_order_History', N'IsCOD') IS NULL
BEGIN
ALTER TABLE [hist].[J11_ele_sale_custom_order_History] ADD [IsCOD] bit NULL;
END;
IF COL_LENGTH(N'stg.J11_ele_sale_custom_order', N'IsCOCQ') IS NULL
BEGIN
ALTER TABLE [stg].[J11_ele_sale_custom_order] ADD [IsCOCQ] bit NULL;
END;
IF COL_LENGTH(N'ods.ele_sale_custom_order', N'IsCOCQ') IS NULL
BEGIN
ALTER TABLE [ods].[ele_sale_custom_order] ADD [IsCOCQ] bit NULL;
END;
IF COL_LENGTH(N'hist.J11_ele_sale_custom_order_History', N'IsCOCQ') IS NULL
BEGIN
ALTER TABLE [hist].[J11_ele_sale_custom_order_History] ADD [IsCOCQ] bit NULL;
END;
IF COL_LENGTH(N'stg.J11_ele_sale_custom_order', N'IsInstall') IS NULL
BEGIN
ALTER TABLE [stg].[J11_ele_sale_custom_order] ADD [IsInstall] bit NULL;
END;
IF COL_LENGTH(N'ods.ele_sale_custom_order', N'IsInstall') IS NULL
BEGIN
ALTER TABLE [ods].[ele_sale_custom_order] ADD [IsInstall] bit NULL;
END;
IF COL_LENGTH(N'hist.J11_ele_sale_custom_order_History', N'IsInstall') IS NULL
BEGIN
ALTER TABLE [hist].[J11_ele_sale_custom_order_History] ADD [IsInstall] bit NULL;
END;
IF COL_LENGTH(N'stg.J11_ele_sale_custom_order', N'IsSetup') IS NULL
BEGIN
ALTER TABLE [stg].[J11_ele_sale_custom_order] ADD [IsSetup] bit NULL;
END;
IF COL_LENGTH(N'ods.ele_sale_custom_order', N'IsSetup') IS NULL
BEGIN
ALTER TABLE [ods].[ele_sale_custom_order] ADD [IsSetup] bit NULL;
END;
IF COL_LENGTH(N'hist.J11_ele_sale_custom_order_History', N'IsSetup') IS NULL
BEGIN
ALTER TABLE [hist].[J11_ele_sale_custom_order_History] ADD [IsSetup] bit NULL;
END;
IF COL_LENGTH(N'stg.J11_ele_sale_custom_order', N'create_date') IS NULL
BEGIN
ALTER TABLE [stg].[J11_ele_sale_custom_order] ADD [create_date] datetime2(6) NULL;
END;
IF COL_LENGTH(N'ods.ele_sale_custom_order', N'create_date') IS NULL
BEGIN
ALTER TABLE [ods].[ele_sale_custom_order] ADD [create_date] datetime2(6) NULL;
END;
IF COL_LENGTH(N'hist.J11_ele_sale_custom_order_History', N'create_date') IS NULL
BEGIN
ALTER TABLE [hist].[J11_ele_sale_custom_order_History] ADD [create_date] datetime2(6) NULL;
END;
IF COL_LENGTH(N'stg.J11_ele_sale_custom_order', N'commitment_date') IS NULL
BEGIN
ALTER TABLE [stg].[J11_ele_sale_custom_order] ADD [commitment_date] datetime2(6) NULL;
END;
IF COL_LENGTH(N'ods.ele_sale_custom_order', N'commitment_date') IS NULL
BEGIN
ALTER TABLE [ods].[ele_sale_custom_order] ADD [commitment_date] datetime2(6) NULL;
END;
IF COL_LENGTH(N'hist.J11_ele_sale_custom_order_History', N'commitment_date') IS NULL
BEGIN
ALTER TABLE [hist].[J11_ele_sale_custom_order_History] ADD [commitment_date] datetime2(6) NULL;
END;
IF COL_LENGTH(N'stg.J11_ele_sale_custom_order', N'date_order') IS NULL
BEGIN
ALTER TABLE [stg].[J11_ele_sale_custom_order] ADD [date_order] datetime2(6) NULL;
END;
IF COL_LENGTH(N'ods.ele_sale_custom_order', N'date_order') IS NULL
BEGIN
ALTER TABLE [ods].[ele_sale_custom_order] ADD [date_order] datetime2(6) NULL;
END;
IF COL_LENGTH(N'hist.J11_ele_sale_custom_order_History', N'date_order') IS NULL
BEGIN
ALTER TABLE [hist].[J11_ele_sale_custom_order_History] ADD [date_order] datetime2(6) NULL;
END;
IF COL_LENGTH(N'stg.J11_ele_sale_custom_order', N'signed_on') IS NULL
BEGIN
ALTER TABLE [stg].[J11_ele_sale_custom_order] ADD [signed_on] datetime2(6) NULL;
END;
IF COL_LENGTH(N'ods.ele_sale_custom_order', N'signed_on') IS NULL
BEGIN
ALTER TABLE [ods].[ele_sale_custom_order] ADD [signed_on] datetime2(6) NULL;
END;
IF COL_LENGTH(N'hist.J11_ele_sale_custom_order_History', N'signed_on') IS NULL
BEGIN
ALTER TABLE [hist].[J11_ele_sale_custom_order_History] ADD [signed_on] datetime2(6) NULL;
END;
IF COL_LENGTH(N'stg.J11_ele_sale_custom_order', N'write_date') IS NULL
BEGIN
ALTER TABLE [stg].[J11_ele_sale_custom_order] ADD [write_date] datetime2(6) NULL;
END;
IF COL_LENGTH(N'ods.ele_sale_custom_order', N'write_date') IS NULL
BEGIN
ALTER TABLE [ods].[ele_sale_custom_order] ADD [write_date] datetime2(6) NULL;
END;
IF COL_LENGTH(N'hist.J11_ele_sale_custom_order_History', N'write_date') IS NULL
BEGIN
ALTER TABLE [hist].[J11_ele_sale_custom_order_History] ADD [write_date] datetime2(6) NULL;
END;
IF COL_LENGTH(N'stg.J11_ele_sale_custom_order', N'prepayment_percent') IS NULL
BEGIN
ALTER TABLE [stg].[J11_ele_sale_custom_order] ADD [prepayment_percent] float NULL;
END;
IF COL_LENGTH(N'ods.ele_sale_custom_order', N'prepayment_percent') IS NULL
BEGIN
ALTER TABLE [ods].[ele_sale_custom_order] ADD [prepayment_percent] float NULL;
END;
IF COL_LENGTH(N'hist.J11_ele_sale_custom_order_History', N'prepayment_percent') IS NULL
BEGIN
ALTER TABLE [hist].[J11_ele_sale_custom_order_History] ADD [prepayment_percent] float NULL;
END;
IF COL_LENGTH(N'stg.J11_ele_sale_custom_order', N'max_discount') IS NULL
BEGIN
ALTER TABLE [stg].[J11_ele_sale_custom_order] ADD [max_discount] float NULL;
END;
IF COL_LENGTH(N'ods.ele_sale_custom_order', N'max_discount') IS NULL
BEGIN
ALTER TABLE [ods].[ele_sale_custom_order] ADD [max_discount] float NULL;
END;
IF COL_LENGTH(N'hist.J11_ele_sale_custom_order_History', N'max_discount') IS NULL
BEGIN
ALTER TABLE [hist].[J11_ele_sale_custom_order_History] ADD [max_discount] float NULL;
END;
IF COL_LENGTH(N'stg.J11_ele_sale_custom_order', N'company_ref') IS NULL
BEGIN
ALTER TABLE [stg].[J11_ele_sale_custom_order] ADD [company_ref] nvarchar(max) NULL;
END;
IF COL_LENGTH(N'ods.ele_sale_custom_order', N'company_ref') IS NULL
BEGIN
ALTER TABLE [ods].[ele_sale_custom_order] ADD [company_ref] nvarchar(max) NULL;
END;
IF COL_LENGTH(N'hist.J11_ele_sale_custom_order_History', N'company_ref') IS NULL
BEGIN
ALTER TABLE [hist].[J11_ele_sale_custom_order_History] ADD [company_ref] nvarchar(max) NULL;
END;
IF COL_LENGTH(N'stg.J11_ele_sale_custom_order', N'trnsp_id') IS NULL
BEGIN
ALTER TABLE [stg].[J11_ele_sale_custom_order] ADD [trnsp_id] int NULL;
END;
IF COL_LENGTH(N'ods.ele_sale_custom_order', N'trnsp_id') IS NULL
BEGIN
ALTER TABLE [ods].[ele_sale_custom_order] ADD [trnsp_id] int NULL;
END;
IF COL_LENGTH(N'hist.J11_ele_sale_custom_order_History', N'trnsp_id') IS NULL
BEGIN
ALTER TABLE [hist].[J11_ele_sale_custom_order_History] ADD [trnsp_id] int NULL;
END;
IF COL_LENGTH(N'stg.J11_ele_sale_custom_order', N'blanket_agreement_id') IS NULL
BEGIN
ALTER TABLE [stg].[J11_ele_sale_custom_order] ADD [blanket_agreement_id] int NULL;
END;
IF COL_LENGTH(N'ods.ele_sale_custom_order', N'blanket_agreement_id') IS NULL
BEGIN
ALTER TABLE [ods].[ele_sale_custom_order] ADD [blanket_agreement_id] int NULL;
END;
IF COL_LENGTH(N'hist.J11_ele_sale_custom_order_History', N'blanket_agreement_id') IS NULL
BEGIN
ALTER TABLE [hist].[J11_ele_sale_custom_order_History] ADD [blanket_agreement_id] int NULL;
END;
IF COL_LENGTH(N'stg.J11_ele_sale_custom_order', N'u_is_issue_invoice') IS NULL
BEGIN
ALTER TABLE [stg].[J11_ele_sale_custom_order] ADD [u_is_issue_invoice] nvarchar(max) NULL;
END;
IF COL_LENGTH(N'ods.ele_sale_custom_order', N'u_is_issue_invoice') IS NULL
BEGIN
ALTER TABLE [ods].[ele_sale_custom_order] ADD [u_is_issue_invoice] nvarchar(max) NULL;
END;
IF COL_LENGTH(N'hist.J11_ele_sale_custom_order_History', N'u_is_issue_invoice') IS NULL
BEGIN
ALTER TABLE [hist].[J11_ele_sale_custom_order_History] ADD [u_is_issue_invoice] nvarchar(max) NULL;
END;
IF COL_LENGTH(N'stg.J11_ele_sale_custom_order', N'docnumber') IS NULL
BEGIN
ALTER TABLE [stg].[J11_ele_sale_custom_order] ADD [docnumber] nvarchar(max) NULL;
END;
IF COL_LENGTH(N'ods.ele_sale_custom_order', N'docnumber') IS NULL
BEGIN
ALTER TABLE [ods].[ele_sale_custom_order] ADD [docnumber] nvarchar(max) NULL;
END;
IF COL_LENGTH(N'hist.J11_ele_sale_custom_order_History', N'docnumber') IS NULL
BEGIN
ALTER TABLE [hist].[J11_ele_sale_custom_order_History] ADD [docnumber] nvarchar(max) NULL;
END;
IF COL_LENGTH(N'stg.J11_ele_sale_custom_order', N'credit_notice') IS NULL
BEGIN
ALTER TABLE [stg].[J11_ele_sale_custom_order] ADD [credit_notice] nvarchar(max) NULL;
END;
IF COL_LENGTH(N'ods.ele_sale_custom_order', N'credit_notice') IS NULL
BEGIN
ALTER TABLE [ods].[ele_sale_custom_order] ADD [credit_notice] nvarchar(max) NULL;
END;
IF COL_LENGTH(N'hist.J11_ele_sale_custom_order_History', N'credit_notice') IS NULL
BEGIN
ALTER TABLE [hist].[J11_ele_sale_custom_order_History] ADD [credit_notice] nvarchar(max) NULL;
END;
IF COL_LENGTH(N'stg.J11_ele_sale_custom_order', N'sap_stt') IS NULL
BEGIN
ALTER TABLE [stg].[J11_ele_sale_custom_order] ADD [sap_stt] int NULL;
END;
IF COL_LENGTH(N'ods.ele_sale_custom_order', N'sap_stt') IS NULL
BEGIN
ALTER TABLE [ods].[ele_sale_custom_order] ADD [sap_stt] int NULL;
END;
IF COL_LENGTH(N'hist.J11_ele_sale_custom_order_History', N'sap_stt') IS NULL
BEGIN
ALTER TABLE [hist].[J11_ele_sale_custom_order_History] ADD [sap_stt] int NULL;
END;
IF COL_LENGTH(N'stg.J11_ele_sale_custom_order', N'sap_u_sino') IS NULL
BEGIN
ALTER TABLE [stg].[J11_ele_sale_custom_order] ADD [sap_u_sino] nvarchar(max) NULL;
END;
IF COL_LENGTH(N'ods.ele_sale_custom_order', N'sap_u_sino') IS NULL
BEGIN
ALTER TABLE [ods].[ele_sale_custom_order] ADD [sap_u_sino] nvarchar(max) NULL;
END;
IF COL_LENGTH(N'hist.J11_ele_sale_custom_order_History', N'sap_u_sino') IS NULL
BEGIN
ALTER TABLE [hist].[J11_ele_sale_custom_order_History] ADD [sap_u_sino] nvarchar(max) NULL;
END;
IF COL_LENGTH(N'stg.J11_ele_sale_custom_order', N'sap_opty_type') IS NULL
BEGIN
ALTER TABLE [stg].[J11_ele_sale_custom_order] ADD [sap_opty_type] nvarchar(max) NULL;
END;
IF COL_LENGTH(N'ods.ele_sale_custom_order', N'sap_opty_type') IS NULL
BEGIN
ALTER TABLE [ods].[ele_sale_custom_order] ADD [sap_opty_type] nvarchar(max) NULL;
END;
IF COL_LENGTH(N'hist.J11_ele_sale_custom_order_History', N'sap_opty_type') IS NULL
BEGIN
ALTER TABLE [hist].[J11_ele_sale_custom_order_History] ADD [sap_opty_type] nvarchar(max) NULL;
END;
IF COL_LENGTH(N'stg.J11_ele_sale_custom_order', N'sap_voucher_no') IS NULL
BEGIN
ALTER TABLE [stg].[J11_ele_sale_custom_order] ADD [sap_voucher_no] nvarchar(max) NULL;
END;
IF COL_LENGTH(N'ods.ele_sale_custom_order', N'sap_voucher_no') IS NULL
BEGIN
ALTER TABLE [ods].[ele_sale_custom_order] ADD [sap_voucher_no] nvarchar(max) NULL;
END;
IF COL_LENGTH(N'hist.J11_ele_sale_custom_order_History', N'sap_voucher_no') IS NULL
BEGIN
ALTER TABLE [hist].[J11_ele_sale_custom_order_History] ADD [sap_voucher_no] nvarchar(max) NULL;
END;
IF COL_LENGTH(N'stg.J11_ele_sale_custom_order', N'sap_status_name') IS NULL
BEGIN
ALTER TABLE [stg].[J11_ele_sale_custom_order] ADD [sap_status_name] nvarchar(max) NULL;
END;
IF COL_LENGTH(N'ods.ele_sale_custom_order', N'sap_status_name') IS NULL
BEGIN
ALTER TABLE [ods].[ele_sale_custom_order] ADD [sap_status_name] nvarchar(max) NULL;
END;
IF COL_LENGTH(N'hist.J11_ele_sale_custom_order_History', N'sap_status_name') IS NULL
BEGIN
ALTER TABLE [hist].[J11_ele_sale_custom_order_History] ADD [sap_status_name] nvarchar(max) NULL;
END;
IF COL_LENGTH(N'stg.J11_ele_sale_custom_order', N'EL_Construction_Address') IS NULL
BEGIN
ALTER TABLE [stg].[J11_ele_sale_custom_order] ADD [EL_Construction_Address] nvarchar(max) NULL;
END;
IF COL_LENGTH(N'ods.ele_sale_custom_order', N'EL_Construction_Address') IS NULL
BEGIN
ALTER TABLE [ods].[ele_sale_custom_order] ADD [EL_Construction_Address] nvarchar(max) NULL;
END;
IF COL_LENGTH(N'hist.J11_ele_sale_custom_order_History', N'EL_Construction_Address') IS NULL
BEGIN
ALTER TABLE [hist].[J11_ele_sale_custom_order_History] ADD [EL_Construction_Address] nvarchar(max) NULL;
END;
IF COL_LENGTH(N'stg.J11_ele_sale_custom_order', N'partner_ref') IS NULL
BEGIN
ALTER TABLE [stg].[J11_ele_sale_custom_order] ADD [partner_ref] nvarchar(max) NULL;
END;
IF COL_LENGTH(N'ods.ele_sale_custom_order', N'partner_ref') IS NULL
BEGIN
ALTER TABLE [ods].[ele_sale_custom_order] ADD [partner_ref] nvarchar(max) NULL;
END;
IF COL_LENGTH(N'hist.J11_ele_sale_custom_order_History', N'partner_ref') IS NULL
BEGIN
ALTER TABLE [hist].[J11_ele_sale_custom_order_History] ADD [partner_ref] nvarchar(max) NULL;
END;
IF COL_LENGTH(N'stg.J11_ele_sale_custom_order', N'u_carcodecommission') IS NULL
BEGIN
ALTER TABLE [stg].[J11_ele_sale_custom_order] ADD [u_carcodecommission] int NULL;
END;
IF COL_LENGTH(N'ods.ele_sale_custom_order', N'u_carcodecommission') IS NULL
BEGIN
ALTER TABLE [ods].[ele_sale_custom_order] ADD [u_carcodecommission] int NULL;
END;
IF COL_LENGTH(N'hist.J11_ele_sale_custom_order_History', N'u_carcodecommission') IS NULL
BEGIN
ALTER TABLE [hist].[J11_ele_sale_custom_order_History] ADD [u_carcodecommission] int NULL;
END;
IF COL_LENGTH(N'stg.J11_ele_sale_custom_order', N'dispatch_notified_by') IS NULL
BEGIN
ALTER TABLE [stg].[J11_ele_sale_custom_order] ADD [dispatch_notified_by] int NULL;
END;
IF COL_LENGTH(N'ods.ele_sale_custom_order', N'dispatch_notified_by') IS NULL
BEGIN
ALTER TABLE [ods].[ele_sale_custom_order] ADD [dispatch_notified_by] int NULL;
END;
IF COL_LENGTH(N'hist.J11_ele_sale_custom_order_History', N'dispatch_notified_by') IS NULL
BEGIN
ALTER TABLE [hist].[J11_ele_sale_custom_order_History] ADD [dispatch_notified_by] int NULL;
END;
IF COL_LENGTH(N'stg.J11_ele_sale_custom_order', N'so_create_result') IS NULL
BEGIN
ALTER TABLE [stg].[J11_ele_sale_custom_order] ADD [so_create_result] nvarchar(max) NULL;
END;
IF COL_LENGTH(N'ods.ele_sale_custom_order', N'so_create_result') IS NULL
BEGIN
ALTER TABLE [ods].[ele_sale_custom_order] ADD [so_create_result] nvarchar(max) NULL;
END;
IF COL_LENGTH(N'hist.J11_ele_sale_custom_order_History', N'so_create_result') IS NULL
BEGIN
ALTER TABLE [hist].[J11_ele_sale_custom_order_History] ADD [so_create_result] nvarchar(max) NULL;
END;
IF COL_LENGTH(N'stg.J11_ele_sale_custom_order', N'so_create_lock_uuid') IS NULL
BEGIN
ALTER TABLE [stg].[J11_ele_sale_custom_order] ADD [so_create_lock_uuid] nvarchar(max) NULL;
END;
IF COL_LENGTH(N'ods.ele_sale_custom_order', N'so_create_lock_uuid') IS NULL
BEGIN
ALTER TABLE [ods].[ele_sale_custom_order] ADD [so_create_lock_uuid] nvarchar(max) NULL;
END;
IF COL_LENGTH(N'hist.J11_ele_sale_custom_order_History', N'so_create_lock_uuid') IS NULL
BEGIN
ALTER TABLE [hist].[J11_ele_sale_custom_order_History] ADD [so_create_lock_uuid] nvarchar(max) NULL;
END;
IF COL_LENGTH(N'stg.J11_ele_sale_custom_order', N'so_idem_key') IS NULL
BEGIN
ALTER TABLE [stg].[J11_ele_sale_custom_order] ADD [so_idem_key] nvarchar(max) NULL;
END;
IF COL_LENGTH(N'ods.ele_sale_custom_order', N'so_idem_key') IS NULL
BEGIN
ALTER TABLE [ods].[ele_sale_custom_order] ADD [so_idem_key] nvarchar(max) NULL;
END;
IF COL_LENGTH(N'hist.J11_ele_sale_custom_order_History', N'so_idem_key') IS NULL
BEGIN
ALTER TABLE [hist].[J11_ele_sale_custom_order_History] ADD [so_idem_key] nvarchar(max) NULL;
END;
IF COL_LENGTH(N'stg.J11_ele_sale_custom_order', N'dispatch_state') IS NULL
BEGIN
ALTER TABLE [stg].[J11_ele_sale_custom_order] ADD [dispatch_state] nvarchar(max) NULL;
END;
IF COL_LENGTH(N'ods.ele_sale_custom_order', N'dispatch_state') IS NULL
BEGIN
ALTER TABLE [ods].[ele_sale_custom_order] ADD [dispatch_state] nvarchar(max) NULL;
END;
IF COL_LENGTH(N'hist.J11_ele_sale_custom_order_History', N'dispatch_state') IS NULL
BEGIN
ALTER TABLE [hist].[J11_ele_sale_custom_order_History] ADD [dispatch_state] nvarchar(max) NULL;
END;
IF COL_LENGTH(N'stg.J11_ele_sale_custom_order', N'dispatch_webhook_key') IS NULL
BEGIN
ALTER TABLE [stg].[J11_ele_sale_custom_order] ADD [dispatch_webhook_key] nvarchar(max) NULL;
END;
IF COL_LENGTH(N'ods.ele_sale_custom_order', N'dispatch_webhook_key') IS NULL
BEGIN
ALTER TABLE [ods].[ele_sale_custom_order] ADD [dispatch_webhook_key] nvarchar(max) NULL;
END;
IF COL_LENGTH(N'hist.J11_ele_sale_custom_order_History', N'dispatch_webhook_key') IS NULL
BEGIN
ALTER TABLE [hist].[J11_ele_sale_custom_order_History] ADD [dispatch_webhook_key] nvarchar(max) NULL;
END;
IF COL_LENGTH(N'stg.J11_ele_sale_custom_order', N'dispatch_note') IS NULL
BEGIN
ALTER TABLE [stg].[J11_ele_sale_custom_order] ADD [dispatch_note] nvarchar(max) NULL;
END;
IF COL_LENGTH(N'ods.ele_sale_custom_order', N'dispatch_note') IS NULL
BEGIN
ALTER TABLE [ods].[ele_sale_custom_order] ADD [dispatch_note] nvarchar(max) NULL;
END;
IF COL_LENGTH(N'hist.J11_ele_sale_custom_order_History', N'dispatch_note') IS NULL
BEGIN
ALTER TABLE [hist].[J11_ele_sale_custom_order_History] ADD [dispatch_note] nvarchar(max) NULL;
END;
IF COL_LENGTH(N'stg.J11_ele_sale_custom_order', N'is_fully_stocked') IS NULL
BEGIN
ALTER TABLE [stg].[J11_ele_sale_custom_order] ADD [is_fully_stocked] bit NULL;
END;
IF COL_LENGTH(N'ods.ele_sale_custom_order', N'is_fully_stocked') IS NULL
BEGIN
ALTER TABLE [ods].[ele_sale_custom_order] ADD [is_fully_stocked] bit NULL;
END;
IF COL_LENGTH(N'hist.J11_ele_sale_custom_order_History', N'is_fully_stocked') IS NULL
BEGIN
ALTER TABLE [hist].[J11_ele_sale_custom_order_History] ADD [is_fully_stocked] bit NULL;
END;
IF COL_LENGTH(N'stg.J11_ele_sale_custom_order', N'so_create_attempted') IS NULL
BEGIN
ALTER TABLE [stg].[J11_ele_sale_custom_order] ADD [so_create_attempted] bit NULL;
END;
IF COL_LENGTH(N'ods.ele_sale_custom_order', N'so_create_attempted') IS NULL
BEGIN
ALTER TABLE [ods].[ele_sale_custom_order] ADD [so_create_attempted] bit NULL;
END;
IF COL_LENGTH(N'hist.J11_ele_sale_custom_order_History', N'so_create_attempted') IS NULL
BEGIN
ALTER TABLE [hist].[J11_ele_sale_custom_order_History] ADD [so_create_attempted] bit NULL;
END;
IF COL_LENGTH(N'stg.J11_ele_sale_custom_order', N'has_commission_line') IS NULL
BEGIN
ALTER TABLE [stg].[J11_ele_sale_custom_order] ADD [has_commission_line] bit NULL;
END;
IF COL_LENGTH(N'ods.ele_sale_custom_order', N'has_commission_line') IS NULL
BEGIN
ALTER TABLE [ods].[ele_sale_custom_order] ADD [has_commission_line] bit NULL;
END;
IF COL_LENGTH(N'hist.J11_ele_sale_custom_order_History', N'has_commission_line') IS NULL
BEGIN
ALTER TABLE [hist].[J11_ele_sale_custom_order_History] ADD [has_commission_line] bit NULL;
END;
IF COL_LENGTH(N'stg.J11_ele_sale_custom_order', N'eta_datetime') IS NULL
BEGIN
ALTER TABLE [stg].[J11_ele_sale_custom_order] ADD [eta_datetime] datetime2(6) NULL;
END;
IF COL_LENGTH(N'ods.ele_sale_custom_order', N'eta_datetime') IS NULL
BEGIN
ALTER TABLE [ods].[ele_sale_custom_order] ADD [eta_datetime] datetime2(6) NULL;
END;
IF COL_LENGTH(N'hist.J11_ele_sale_custom_order_History', N'eta_datetime') IS NULL
BEGIN
ALTER TABLE [hist].[J11_ele_sale_custom_order_History] ADD [eta_datetime] datetime2(6) NULL;
END;
IF COL_LENGTH(N'stg.J11_ele_sale_custom_order', N'so_create_attempted_at') IS NULL
BEGIN
ALTER TABLE [stg].[J11_ele_sale_custom_order] ADD [so_create_attempted_at] datetime2(6) NULL;
END;
IF COL_LENGTH(N'ods.ele_sale_custom_order', N'so_create_attempted_at') IS NULL
BEGIN
ALTER TABLE [ods].[ele_sale_custom_order] ADD [so_create_attempted_at] datetime2(6) NULL;
END;
IF COL_LENGTH(N'hist.J11_ele_sale_custom_order_History', N'so_create_attempted_at') IS NULL
BEGIN
ALTER TABLE [hist].[J11_ele_sale_custom_order_History] ADD [so_create_attempted_at] datetime2(6) NULL;
END;
IF COL_LENGTH(N'stg.J11_ele_sale_custom_order', N'dispatch_notified_at') IS NULL
BEGIN
ALTER TABLE [stg].[J11_ele_sale_custom_order] ADD [dispatch_notified_at] datetime2(6) NULL;
END;
IF COL_LENGTH(N'ods.ele_sale_custom_order', N'dispatch_notified_at') IS NULL
BEGIN
ALTER TABLE [ods].[ele_sale_custom_order] ADD [dispatch_notified_at] datetime2(6) NULL;
END;
IF COL_LENGTH(N'hist.J11_ele_sale_custom_order_History', N'dispatch_notified_at') IS NULL
BEGIN
ALTER TABLE [hist].[J11_ele_sale_custom_order_History] ADD [dispatch_notified_at] datetime2(6) NULL;
END;
IF COL_LENGTH(N'stg.J11_ele_sale_custom_order', N'dispatch_send_count') IS NULL
BEGIN
ALTER TABLE [stg].[J11_ele_sale_custom_order] ADD [dispatch_send_count] int NULL;
END;
IF COL_LENGTH(N'ods.ele_sale_custom_order', N'dispatch_send_count') IS NULL
BEGIN
ALTER TABLE [ods].[ele_sale_custom_order] ADD [dispatch_send_count] int NULL;
END;
IF COL_LENGTH(N'hist.J11_ele_sale_custom_order_History', N'dispatch_send_count') IS NULL
BEGIN
ALTER TABLE [hist].[J11_ele_sale_custom_order_History] ADD [dispatch_send_count] int NULL;
END;
IF COL_LENGTH(N'stg.J11_ele_sale_custom_order', N'pay_last_remark') IS NULL
BEGIN
ALTER TABLE [stg].[J11_ele_sale_custom_order] ADD [pay_last_remark] nvarchar(max) NULL;
END;
IF COL_LENGTH(N'ods.ele_sale_custom_order', N'pay_last_remark') IS NULL
BEGIN
ALTER TABLE [ods].[ele_sale_custom_order] ADD [pay_last_remark] nvarchar(max) NULL;
END;
IF COL_LENGTH(N'hist.J11_ele_sale_custom_order_History', N'pay_last_remark') IS NULL
BEGIN
ALTER TABLE [hist].[J11_ele_sale_custom_order_History] ADD [pay_last_remark] nvarchar(max) NULL;
END;
IF COL_LENGTH(N'stg.J11_ele_sale_custom_order', N'pay_updated_at') IS NULL
BEGIN
ALTER TABLE [stg].[J11_ele_sale_custom_order] ADD [pay_updated_at] datetime2(6) NULL;
END;
IF COL_LENGTH(N'ods.ele_sale_custom_order', N'pay_updated_at') IS NULL
BEGIN
ALTER TABLE [ods].[ele_sale_custom_order] ADD [pay_updated_at] datetime2(6) NULL;
END;
IF COL_LENGTH(N'hist.J11_ele_sale_custom_order_History', N'pay_updated_at') IS NULL
BEGIN
ALTER TABLE [hist].[J11_ele_sale_custom_order_History] ADD [pay_updated_at] datetime2(6) NULL;
END;
IF COL_LENGTH(N'stg.J11_ele_sale_custom_order', N'pay_accumulated') IS NULL
BEGIN
ALTER TABLE [stg].[J11_ele_sale_custom_order] ADD [pay_accumulated] float NULL;
END;
IF COL_LENGTH(N'ods.ele_sale_custom_order', N'pay_accumulated') IS NULL
BEGIN
ALTER TABLE [ods].[ele_sale_custom_order] ADD [pay_accumulated] float NULL;
END;
IF COL_LENGTH(N'hist.J11_ele_sale_custom_order_History', N'pay_accumulated') IS NULL
BEGIN
ALTER TABLE [hist].[J11_ele_sale_custom_order_History] ADD [pay_accumulated] float NULL;
END;
IF COL_LENGTH(N'stg.J11_ele_sale_custom_order', N'pay_last_amount') IS NULL
BEGIN
ALTER TABLE [stg].[J11_ele_sale_custom_order] ADD [pay_last_amount] float NULL;
END;
IF COL_LENGTH(N'ods.ele_sale_custom_order', N'pay_last_amount') IS NULL
BEGIN
ALTER TABLE [ods].[ele_sale_custom_order] ADD [pay_last_amount] float NULL;
END;
IF COL_LENGTH(N'hist.J11_ele_sale_custom_order_History', N'pay_last_amount') IS NULL
BEGIN
ALTER TABLE [hist].[J11_ele_sale_custom_order_History] ADD [pay_last_amount] float NULL;
END;
IF COL_LENGTH(N'stg.J11_ele_sale_custom_order', N'sap_completed_at_hist') IS NULL
BEGIN
ALTER TABLE [stg].[J11_ele_sale_custom_order] ADD [sap_completed_at_hist] nvarchar(max) NULL;
END;
IF COL_LENGTH(N'ods.ele_sale_custom_order', N'sap_completed_at_hist') IS NULL
BEGIN
ALTER TABLE [ods].[ele_sale_custom_order] ADD [sap_completed_at_hist] nvarchar(max) NULL;
END;
IF COL_LENGTH(N'hist.J11_ele_sale_custom_order_History', N'sap_completed_at_hist') IS NULL
BEGIN
ALTER TABLE [hist].[J11_ele_sale_custom_order_History] ADD [sap_completed_at_hist] nvarchar(max) NULL;
END;
IF COL_LENGTH(N'stg.J11_ele_sale_custom_order', N'sap_completed_at') IS NULL
BEGIN
ALTER TABLE [stg].[J11_ele_sale_custom_order] ADD [sap_completed_at] datetime2(6) NULL;
END;
IF COL_LENGTH(N'ods.ele_sale_custom_order', N'sap_completed_at') IS NULL
BEGIN
ALTER TABLE [ods].[ele_sale_custom_order] ADD [sap_completed_at] datetime2(6) NULL;
END;
IF COL_LENGTH(N'hist.J11_ele_sale_custom_order_History', N'sap_completed_at') IS NULL
BEGIN
ALTER TABLE [hist].[J11_ele_sale_custom_order_History] ADD [sap_completed_at] datetime2(6) NULL;
END;
IF COL_LENGTH(N'stg.J11_ele_sale_custom_order', N'credit_auto_pass') IS NULL
BEGIN
ALTER TABLE [stg].[J11_ele_sale_custom_order] ADD [credit_auto_pass] bit NULL;
END;
IF COL_LENGTH(N'ods.ele_sale_custom_order', N'credit_auto_pass') IS NULL
BEGIN
ALTER TABLE [ods].[ele_sale_custom_order] ADD [credit_auto_pass] bit NULL;
END;
IF COL_LENGTH(N'hist.J11_ele_sale_custom_order_History', N'credit_auto_pass') IS NULL
BEGIN
ALTER TABLE [hist].[J11_ele_sale_custom_order_History] ADD [credit_auto_pass] bit NULL;
END;
IF COL_LENGTH(N'stg.J11_ele_sale_custom_order', N'auto_be_promotion_log') IS NULL
BEGIN
ALTER TABLE [stg].[J11_ele_sale_custom_order] ADD [auto_be_promotion_log] nvarchar(max) NULL;
END;
IF COL_LENGTH(N'ods.ele_sale_custom_order', N'auto_be_promotion_log') IS NULL
BEGIN
ALTER TABLE [ods].[ele_sale_custom_order] ADD [auto_be_promotion_log] nvarchar(max) NULL;
END;
IF COL_LENGTH(N'hist.J11_ele_sale_custom_order_History', N'auto_be_promotion_log') IS NULL
BEGIN
ALTER TABLE [hist].[J11_ele_sale_custom_order_History] ADD [auto_be_promotion_log] nvarchar(max) NULL;
END;
IF COL_LENGTH(N'stg.J11_ele_sale_custom_order', N'auto_be_promotion_last_sync') IS NULL
BEGIN
ALTER TABLE [stg].[J11_ele_sale_custom_order] ADD [auto_be_promotion_last_sync] datetime2(6) NULL;
END;
IF COL_LENGTH(N'ods.ele_sale_custom_order', N'auto_be_promotion_last_sync') IS NULL
BEGIN
ALTER TABLE [ods].[ele_sale_custom_order] ADD [auto_be_promotion_last_sync] datetime2(6) NULL;
END;
IF COL_LENGTH(N'hist.J11_ele_sale_custom_order_History', N'auto_be_promotion_last_sync') IS NULL
BEGIN
ALTER TABLE [hist].[J11_ele_sale_custom_order_History] ADD [auto_be_promotion_last_sync] datetime2(6) NULL;
END;
IF COL_LENGTH(N'stg.J11_ele_sale_custom_order', N'promotion_reason_id') IS NULL
BEGIN
ALTER TABLE [stg].[J11_ele_sale_custom_order] ADD [promotion_reason_id] int NULL;
END;
IF COL_LENGTH(N'ods.ele_sale_custom_order', N'promotion_reason_id') IS NULL
BEGIN
ALTER TABLE [ods].[ele_sale_custom_order] ADD [promotion_reason_id] int NULL;
END;
IF COL_LENGTH(N'hist.J11_ele_sale_custom_order_History', N'promotion_reason_id') IS NULL
BEGIN
ALTER TABLE [hist].[J11_ele_sale_custom_order_History] ADD [promotion_reason_id] int NULL;
END;
IF COL_LENGTH(N'stg.J11_ele_sale_custom_order', N'oms_eta_warning_message') IS NULL
BEGIN
ALTER TABLE [stg].[J11_ele_sale_custom_order] ADD [oms_eta_warning_message] nvarchar(max) NULL;
END;
IF COL_LENGTH(N'ods.ele_sale_custom_order', N'oms_eta_warning_message') IS NULL
BEGIN
ALTER TABLE [ods].[ele_sale_custom_order] ADD [oms_eta_warning_message] nvarchar(max) NULL;
END;
IF COL_LENGTH(N'hist.J11_ele_sale_custom_order_History', N'oms_eta_warning_message') IS NULL
BEGIN
ALTER TABLE [hist].[J11_ele_sale_custom_order_History] ADD [oms_eta_warning_message] nvarchar(max) NULL;
END;
IF COL_LENGTH(N'stg.J11_ele_sale_custom_order', N'oms_dispatch_eta_notified') IS NULL
BEGIN
ALTER TABLE [stg].[J11_ele_sale_custom_order] ADD [oms_dispatch_eta_notified] bit NULL;
END;
IF COL_LENGTH(N'ods.ele_sale_custom_order', N'oms_dispatch_eta_notified') IS NULL
BEGIN
ALTER TABLE [ods].[ele_sale_custom_order] ADD [oms_dispatch_eta_notified] bit NULL;
END;
IF COL_LENGTH(N'hist.J11_ele_sale_custom_order_History', N'oms_dispatch_eta_notified') IS NULL
BEGIN
ALTER TABLE [hist].[J11_ele_sale_custom_order_History] ADD [oms_dispatch_eta_notified] bit NULL;
END;
IF COL_LENGTH(N'stg.J11_ele_sale_custom_order', N'oms_dispatch_upcoming_notified') IS NULL
BEGIN
ALTER TABLE [stg].[J11_ele_sale_custom_order] ADD [oms_dispatch_upcoming_notified] bit NULL;
END;
IF COL_LENGTH(N'ods.ele_sale_custom_order', N'oms_dispatch_upcoming_notified') IS NULL
BEGIN
ALTER TABLE [ods].[ele_sale_custom_order] ADD [oms_dispatch_upcoming_notified] bit NULL;
END;
IF COL_LENGTH(N'hist.J11_ele_sale_custom_order_History', N'oms_dispatch_upcoming_notified') IS NULL
BEGIN
ALTER TABLE [hist].[J11_ele_sale_custom_order_History] ADD [oms_dispatch_upcoming_notified] bit NULL;
END;
IF COL_LENGTH(N'stg.J11_ele_sale_custom_order', N'oms_has_eta_adjustment') IS NULL
BEGIN
ALTER TABLE [stg].[J11_ele_sale_custom_order] ADD [oms_has_eta_adjustment] bit NULL;
END;
IF COL_LENGTH(N'ods.ele_sale_custom_order', N'oms_has_eta_adjustment') IS NULL
BEGIN
ALTER TABLE [ods].[ele_sale_custom_order] ADD [oms_has_eta_adjustment] bit NULL;
END;
IF COL_LENGTH(N'hist.J11_ele_sale_custom_order_History', N'oms_has_eta_adjustment') IS NULL
BEGIN
ALTER TABLE [hist].[J11_ele_sale_custom_order_History] ADD [oms_has_eta_adjustment] bit NULL;
END;
IF COL_LENGTH(N'stg.J11_ele_sale_custom_order', N'oms_eta_exceeds_delivery') IS NULL
BEGIN
ALTER TABLE [stg].[J11_ele_sale_custom_order] ADD [oms_eta_exceeds_delivery] bit NULL;
END;
IF COL_LENGTH(N'ods.ele_sale_custom_order', N'oms_eta_exceeds_delivery') IS NULL
BEGIN
ALTER TABLE [ods].[ele_sale_custom_order] ADD [oms_eta_exceeds_delivery] bit NULL;
END;
IF COL_LENGTH(N'hist.J11_ele_sale_custom_order_History', N'oms_eta_exceeds_delivery') IS NULL
BEGIN
ALTER TABLE [hist].[J11_ele_sale_custom_order_History] ADD [oms_eta_exceeds_delivery] bit NULL;
END;
IF COL_LENGTH(N'stg.J11_ele_sale_custom_order', N'oms_submitted_for_approval_at') IS NULL
BEGIN
ALTER TABLE [stg].[J11_ele_sale_custom_order] ADD [oms_submitted_for_approval_at] datetime2(6) NULL;
END;
IF COL_LENGTH(N'ods.ele_sale_custom_order', N'oms_submitted_for_approval_at') IS NULL
BEGIN
ALTER TABLE [ods].[ele_sale_custom_order] ADD [oms_submitted_for_approval_at] datetime2(6) NULL;
END;
IF COL_LENGTH(N'hist.J11_ele_sale_custom_order_History', N'oms_submitted_for_approval_at') IS NULL
BEGIN
ALTER TABLE [hist].[J11_ele_sale_custom_order_History] ADD [oms_submitted_for_approval_at] datetime2(6) NULL;
END;
IF COL_LENGTH(N'stg.J11_ele_sale_custom_order', N'oms_credit_approved_at') IS NULL
BEGIN
ALTER TABLE [stg].[J11_ele_sale_custom_order] ADD [oms_credit_approved_at] datetime2(6) NULL;
END;
IF COL_LENGTH(N'ods.ele_sale_custom_order', N'oms_credit_approved_at') IS NULL
BEGIN
ALTER TABLE [ods].[ele_sale_custom_order] ADD [oms_credit_approved_at] datetime2(6) NULL;
END;
IF COL_LENGTH(N'hist.J11_ele_sale_custom_order_History', N'oms_credit_approved_at') IS NULL
BEGIN
ALTER TABLE [hist].[J11_ele_sale_custom_order_History] ADD [oms_credit_approved_at] datetime2(6) NULL;
END;
IF COL_LENGTH(N'stg.J11_ele_sale_custom_order', N'oms_max_eta_done') IS NULL
BEGIN
ALTER TABLE [stg].[J11_ele_sale_custom_order] ADD [oms_max_eta_done] datetime2(6) NULL;
END;
IF COL_LENGTH(N'ods.ele_sale_custom_order', N'oms_max_eta_done') IS NULL
BEGIN
ALTER TABLE [ods].[ele_sale_custom_order] ADD [oms_max_eta_done] datetime2(6) NULL;
END;
IF COL_LENGTH(N'hist.J11_ele_sale_custom_order_History', N'oms_max_eta_done') IS NULL
BEGIN
ALTER TABLE [hist].[J11_ele_sale_custom_order_History] ADD [oms_max_eta_done] datetime2(6) NULL;
END;
IF COL_LENGTH(N'stg.J11_ele_sale_custom_order', N'oms_eta_sla_deadline') IS NULL
BEGIN
ALTER TABLE [stg].[J11_ele_sale_custom_order] ADD [oms_eta_sla_deadline] datetime2(6) NULL;
END;
IF COL_LENGTH(N'ods.ele_sale_custom_order', N'oms_eta_sla_deadline') IS NULL
BEGIN
ALTER TABLE [ods].[ele_sale_custom_order] ADD [oms_eta_sla_deadline] datetime2(6) NULL;
END;
IF COL_LENGTH(N'hist.J11_ele_sale_custom_order_History', N'oms_eta_sla_deadline') IS NULL
BEGIN
ALTER TABLE [hist].[J11_ele_sale_custom_order_History] ADD [oms_eta_sla_deadline] datetime2(6) NULL;
END;
IF COL_LENGTH(N'stg.J11_ele_sale_custom_order', N'oms_eta_sla_hours') IS NULL
BEGIN
ALTER TABLE [stg].[J11_ele_sale_custom_order] ADD [oms_eta_sla_hours] float NULL;
END;
IF COL_LENGTH(N'ods.ele_sale_custom_order', N'oms_eta_sla_hours') IS NULL
BEGIN
ALTER TABLE [ods].[ele_sale_custom_order] ADD [oms_eta_sla_hours] float NULL;
END;
IF COL_LENGTH(N'hist.J11_ele_sale_custom_order_History', N'oms_eta_sla_hours') IS NULL
BEGIN
ALTER TABLE [hist].[J11_ele_sale_custom_order_History] ADD [oms_eta_sla_hours] float NULL;
END;
IF COL_LENGTH(N'stg.J11_ele_sale_custom_order', N'approval_rejected_step_name') IS NULL
BEGIN
ALTER TABLE [stg].[J11_ele_sale_custom_order] ADD [approval_rejected_step_name] nvarchar(max) NULL;
END;
IF COL_LENGTH(N'ods.ele_sale_custom_order', N'approval_rejected_step_name') IS NULL
BEGIN
ALTER TABLE [ods].[ele_sale_custom_order] ADD [approval_rejected_step_name] nvarchar(max) NULL;
END;
IF COL_LENGTH(N'hist.J11_ele_sale_custom_order_History', N'approval_rejected_step_name') IS NULL
BEGIN
ALTER TABLE [hist].[J11_ele_sale_custom_order_History] ADD [approval_rejected_step_name] nvarchar(max) NULL;
END;
IF COL_LENGTH(N'stg.J11_ele_sale_custom_order', N'oms_late_dispatch_alert_sent') IS NULL
BEGIN
ALTER TABLE [stg].[J11_ele_sale_custom_order] ADD [oms_late_dispatch_alert_sent] bit NULL;
END;
IF COL_LENGTH(N'ods.ele_sale_custom_order', N'oms_late_dispatch_alert_sent') IS NULL
BEGIN
ALTER TABLE [ods].[ele_sale_custom_order] ADD [oms_late_dispatch_alert_sent] bit NULL;
END;
IF COL_LENGTH(N'hist.J11_ele_sale_custom_order_History', N'oms_late_dispatch_alert_sent') IS NULL
BEGIN
ALTER TABLE [hist].[J11_ele_sale_custom_order_History] ADD [oms_late_dispatch_alert_sent] bit NULL;
END;
IF COL_LENGTH(N'stg.J11_ele_sale_custom_order', N'oms_late_dispatch_alert_sent_at') IS NULL
BEGIN
ALTER TABLE [stg].[J11_ele_sale_custom_order] ADD [oms_late_dispatch_alert_sent_at] datetime2(6) NULL;
END;
IF COL_LENGTH(N'ods.ele_sale_custom_order', N'oms_late_dispatch_alert_sent_at') IS NULL
BEGIN
ALTER TABLE [ods].[ele_sale_custom_order] ADD [oms_late_dispatch_alert_sent_at] datetime2(6) NULL;
END;
IF COL_LENGTH(N'hist.J11_ele_sale_custom_order_History', N'oms_late_dispatch_alert_sent_at') IS NULL
BEGIN
ALTER TABLE [hist].[J11_ele_sale_custom_order_History] ADD [oms_late_dispatch_alert_sent_at] datetime2(6) NULL;
END;
IF COL_LENGTH(N'stg.J11_ele_sale_custom_order', N'so_create_lock_at') IS NULL
BEGIN
ALTER TABLE [stg].[J11_ele_sale_custom_order] ADD [so_create_lock_at] datetime2(6) NULL;
END;
IF COL_LENGTH(N'ods.ele_sale_custom_order', N'so_create_lock_at') IS NULL
BEGIN
ALTER TABLE [ods].[ele_sale_custom_order] ADD [so_create_lock_at] datetime2(6) NULL;
END;
IF COL_LENGTH(N'hist.J11_ele_sale_custom_order_History', N'so_create_lock_at') IS NULL
BEGIN
ALTER TABLE [hist].[J11_ele_sale_custom_order_History] ADD [so_create_lock_at] datetime2(6) NULL;
END;
IF COL_LENGTH(N'stg.J11_ele_sale_custom_order', N'EL_Elevator_Code') IS NULL
BEGIN
ALTER TABLE [stg].[J11_ele_sale_custom_order] ADD [EL_Elevator_Code] nvarchar(max) NULL;
END;
IF COL_LENGTH(N'ods.ele_sale_custom_order', N'EL_Elevator_Code') IS NULL
BEGIN
ALTER TABLE [ods].[ele_sale_custom_order] ADD [EL_Elevator_Code] nvarchar(max) NULL;
END;
IF COL_LENGTH(N'hist.J11_ele_sale_custom_order_History', N'EL_Elevator_Code') IS NULL
BEGIN
ALTER TABLE [hist].[J11_ele_sale_custom_order_History] ADD [EL_Elevator_Code] nvarchar(max) NULL;
END;
IF COL_LENGTH(N'stg.J11_ele_sale_custom_order', N'sap_inv_no') IS NULL
BEGIN
ALTER TABLE [stg].[J11_ele_sale_custom_order] ADD [sap_inv_no] nvarchar(max) NULL;
END;
IF COL_LENGTH(N'ods.ele_sale_custom_order', N'sap_inv_no') IS NULL
BEGIN
ALTER TABLE [ods].[ele_sale_custom_order] ADD [sap_inv_no] nvarchar(max) NULL;
END;
IF COL_LENGTH(N'hist.J11_ele_sale_custom_order_History', N'sap_inv_no') IS NULL
BEGIN
ALTER TABLE [hist].[J11_ele_sale_custom_order_History] ADD [sap_inv_no] nvarchar(max) NULL;
END;
IF COL_LENGTH(N'stg.J11_ele_sale_custom_order', N'sap_status_sync_error') IS NULL
BEGIN
ALTER TABLE [stg].[J11_ele_sale_custom_order] ADD [sap_status_sync_error] nvarchar(max) NULL;
END;
IF COL_LENGTH(N'ods.ele_sale_custom_order', N'sap_status_sync_error') IS NULL
BEGIN
ALTER TABLE [ods].[ele_sale_custom_order] ADD [sap_status_sync_error] nvarchar(max) NULL;
END;
IF COL_LENGTH(N'hist.J11_ele_sale_custom_order_History', N'sap_status_sync_error') IS NULL
BEGIN
ALTER TABLE [hist].[J11_ele_sale_custom_order_History] ADD [sap_status_sync_error] nvarchar(max) NULL;
END;
IF COL_LENGTH(N'stg.J11_ele_sale_custom_order', N'sap_status_sync_at') IS NULL
BEGIN
ALTER TABLE [stg].[J11_ele_sale_custom_order] ADD [sap_status_sync_at] datetime2(6) NULL;
END;
IF COL_LENGTH(N'ods.ele_sale_custom_order', N'sap_status_sync_at') IS NULL
BEGIN
ALTER TABLE [ods].[ele_sale_custom_order] ADD [sap_status_sync_at] datetime2(6) NULL;
END;
IF COL_LENGTH(N'hist.J11_ele_sale_custom_order_History', N'sap_status_sync_at') IS NULL
BEGIN
ALTER TABLE [hist].[J11_ele_sale_custom_order_History] ADD [sap_status_sync_at] datetime2(6) NULL;
END;
IF NOT EXISTS
(
SELECT 1
FROM sys.indexes AS indexes
INNER JOIN sys.index_columns AS first_column
ON first_column.[object_id] = indexes.[object_id]
AND first_column.[index_id] = indexes.[index_id]
AND first_column.[key_ordinal] = 1
INNER JOIN sys.columns AS first_column_name
ON first_column_name.[object_id] = first_column.[object_id]
AND first_column_name.[column_id] = first_column.[column_id]
INNER JOIN sys.index_columns AS second_column
ON second_column.[object_id] = indexes.[object_id]
AND second_column.[index_id] = indexes.[index_id]
AND second_column.[key_ordinal] = 2
INNER JOIN sys.columns AS second_column_name
ON second_column_name.[object_id] = second_column.[object_id]
AND second_column_name.[column_id] = second_column.[column_id]
WHERE indexes.[object_id] = OBJECT_ID(N'ods.ele_sale_custom_order')
AND first_column_name.[name] = N'sync_source_id'
AND second_column_name.[name] = N'id'
)
CREATE INDEX [IX_ele_sale_custom_order_SyncSource_Key] ON [ods].[ele_sale_custom_order] ([sync_source_id], [id]);
IF NOT EXISTS (SELECT 1 FROM sys.indexes WHERE object_id = OBJECT_ID(N'ods.ele_sale_custom_order') AND name = N'IX_ele_sale_custom_order_UpdatedAt_Id')
CREATE INDEX [IX_ele_sale_custom_order_UpdatedAt_Id] ON [ods].[ele_sale_custom_order] ([write_date], [id]);
IF NOT EXISTS (SELECT 1 FROM sys.indexes WHERE object_id = OBJECT_ID(N'ods.ele_sale_custom_order') AND name = N'IX_ele_sale_custom_order_IsDeleted')
CREATE INDEX [IX_ele_sale_custom_order_IsDeleted] ON [ods].[ele_sale_custom_order] ([sync_is_deleted]);
IF NOT EXISTS (SELECT 1 FROM sys.indexes WHERE object_id = OBJECT_ID(N'hist.J11_ele_sale_custom_order_History') AND name = N'IX_J11_ele_sale_custom_order_History_Record')
CREATE INDEX [IX_J11_ele_sale_custom_order_History_Record] ON [hist].[J11_ele_sale_custom_order_History] ([sync_source_id], [source_record_id], [is_current]);