MULTIPLE INSERT OVERWRITE in HIVE - hive

I'm trying to do multiple insert overwrite in Hive by the following commands.
INSERT OVERWRITE table results_3 SELECT NULL, res, NULL, NULL FROM results where field= 'title';
And the content of results_3 table after the first command
NULL Up On Cripple Creek (2000 Digital Remaster) NULL NULL
NULL The Weight (2000 Digital Remaster) NULL NULL
NULL Rhythm Of The Rain (LP Version) NULL NULL
NULL Who'll Stop the Rain NULL NULL
NULL I Walk the Line NULL NULL
NULL Against The Wind NULL NULL
NULL Lyin' Eyes NULL NULL
NULL North To Alaska NULL NULL
NULL You Gave Me A Mountain NULL NULL
NULL Night Moves NULL NULL
INSERT OVERWRITE table results_3 SELECT NULL, NULL, res, NULL FROM results where field= 'albums';
And the content of results_3 table after the second command
NULL NULL The Band NULL
NULL NULL The Band NULL
NULL NULL The Cascades NULL
NULL NULL Creedence Clearwater Revival NULL
NULL NULL Johnny Cash NULL
NULL NULL Bob Seger NULL
NULL NULL The Eagles NULL
NULL NULL Johnny Horton NULL
NULL NULL Marty Robbins NULL
NULL NULL Bob Seger NULL
but I want to merge the two things together. Do you have any idea how I can tackle this?
Thanks

You can append in such way:
INSERT OVERWRITE TABLE
select col1 ... col2
from
(
SELECT col1 ... coln from TABLE --old data
UNION ALL
SELECT col1 ... col2n from TABLE2 --new data
)

Hive insert does not support append so far.
A simple way : insert overwrite two directory. Merge it manually.
Or
insert into a table with different partition(But, in fact different partition have different directory).
Plz see hive wiki for more information.

Related

Merge Multiple SQL Table Columns into One

I have a table as such (with thousand of rows):
ogr_fid (PK, int, not null)
90 (varchar(157), null)
80 (varchar(157), null)
70 (varchar(157), null)
1
some_text
NULL
NULL
2
NULL
NULL
other_text
3
NULL
more_text
NULL
4
even_more_text
NULL
NULL
5
NULL
NULL
NULL
I would like to merge the table to read as follows;
ogr_fid (PK, int, not null)
m_agl (int, null)
1
90
2
70
3
80
4
90
5
NULL
As you can see I will use the text as simply a IS NOT NULL sort of test. The merged column will be populated with the name of the IS NOT NULL column.
I have been trying to understand IIF and CASE but it is far beyond my current level of understanding without a working example to learn from.
My latest attempt:
ALTER TABLE [dbo].[my_table] ADD [m_agl] AS SELECT
CASE WHEN 90 IS NOT NULL THEN '90'
CASE WHEN 80 IS NOT NULL THEN '80'
CASE WHEN 70 IS NOT NULL THEN '70'
GO
ALTER TABLE [dbo].[my_table] DROP COLUMN (90, 80, 70)
GO
Many thanks.
Note, a Column name cannot be naked integer.
Solution using IIF
ALTER TABLE [dbo].[my_table] ADD [column_merged];
GO
SELECT ogr_fid, IIF(column_1 IS NOT NULL, column_1, IIF(column_2 IS NOT NULL, column_2, IIF(column_3 IS NOT NULL, column_3, NULL)))
FROM dbo.my_table;
GO
ALTER TABLE [dbo].[my_table] DROP COLUMN (column_1, column_2, column_3);
GO
Learn more about CASE at Microsoft Docs
Learn more about IIF at Microsoft Docs

"Query processor ran out of internal resources and could not produce a query plan" for MERGE with 2,600 records and one key field

So I'm writing a Visual Studio SQL database project for an existing database.
I'm generating simple merge scripts per table for standing data, existing data so on and so forth. It's been relatively straight forward until I come to one particular table which is giving me the error in the title.
Now, if this was a complex query I'd understand, but it's not, it has one key field with a clustered index and no complex operations. I have tried removing all of the ISNULL checks from the MATCHED check after the first AND and it still gives me the same error. I don't understand!
They key is [my_table_code], the first column. Here is the bulk of the query with only the first row for clarity.
MERGE INTO [my_table] AS Target
USING (VALUES
(N'00001L',N'20160425',N'20160425',N'132011',N'DMTEAM',N'C',N'Name',N'F',365,0,N'19790702',N'20130418',N'20130418',N'20130418',N'20130418',N'',0.0,0.0,0,N'GBP',1.0,N'19790702',N'N',N'N',0,0,0,0,N'Y',N'SLAC Life Series 1',N'19790703',365,N'UK',-1,N'N',N'H',N'N',0,N'',N'ALL',N'10000101',N'',0,0,N'0',N'N',N'N',0.000000000000000e+000,N'',N'E',365,0,0,N'N',365,0,0,N'N',0,0,N'',N'',0,N'',N'DEF',N'',N'',0,0,N'',N'',-1,N' ',N' ',N' ',N' ',N' ',N'E',N' ',N'',N' ',N' ',N' ',0,1.5,4.5,7.5,0.0,0,N'0',N'0')
-- 2600 rows more
) AS Source ([my_table_code],[my_table_create_date],[my_table_last_updt_date],[my_table_last_updt_time],[my_table_last_updt_userid],[my_table_record_status],[my_table_name],[my_table_next_or_last_price],[my_table_pricing_frequency],[my_table_sell_pricing_frequency],[my_table_commenced_date],[my_table_closed_date],[my_table_closed_for_newbus_date],[my_table_closed_for_spi_date],[my_table_closed_for_money_date],[my_table_category],[my_table_spread_relationship],[my_table_management_charge],[my_table_sellout_period_mths],[my_table_currency],[my_table_price_tolerance],[my_table_initial_price_date],[my_table_last_date_in_period],[my_table_sell_last_date_in_period],[my_table_last_day_in_period],[my_table_sell_last_day_in_period],[my_table_same_day_in_period],[my_table_sell_same_day_in_period],[my_table_use_working_days],[my_table_external_id],[my_table_post_initial_price_date],[my_table_price_applies_frequency],[my_table_price_country_code],[my_table_non_working_price_days_adj],[my_table_pricing_calendar],[my_table_risk_profile],[my_table_pay_dividend],[my_table_dividend_frequency],[my_table_sedol],[my_table_type],[my_table_strike_date],[my_table_maturity_date],[my_table_amc_basis_no],[my_table_coupon_select_id],[my_table_coupon_defaults],[my_table_whole_units],[my_table_clone_by_policy],[my_table_initial_clone_price],[my_table_price_base_calc_date],[my_table_group],[my_table_disinv_notice_freq],[my_table_disinv_notice_value],[my_table_disinv_same_day_in_period],[my_table_disinv_notice_last_date],[my_table_trade_cutoff_freq],[my_table_trade_cutoff_value],[my_table_trade_cutoff_same_day_in_period],[my_table_trade_cutoff_last_date],[my_table_expected_delay_rules],[my_table_settlement_days],[my_table_bid_offer_exception_rules],[my_table_holding_fund_id],[my_table_timeout_days],[my_table_price_valuation_basis],[my_table_classification],[my_table_target_days],[my_table_sell_target_days],[my_table_disinv_same_day_period_skip],[my_table_trade_cutoff_same_day_period_skip],[my_table_equity_sector],[my_table_client_classification],[my_table_max_decimal_places],[my_table_rounding_method],[my_table_closing_time],[my_table_rounding_direction],[my_table_use_external_WS],[my_table_gl_code],[my_table_asset_class],[my_table_grouping],[my_table_factsheet_url],[my_table_aladdin_ticker],[my_table_manager],[my_table_use_notice_for_backdates],[my_table_business_date_delay],[my_table_growth_low],[my_table_growth_med],[my_table_growth_high],[my_table_growth_SMPI],[my_table_instruction_file_decimal_places],[my_table_suspend_start_date],[my_table_suspend_end_date])
ON (Target.[my_table_code] = Source.[my_table_code])
WHEN MATCHED AND (
NULLIF(Source.[my_table_create_date], Target.[my_table_create_date]) IS NOT NULL OR NULLIF(Target.[my_table_create_date], Source.[my_table_create_date]) IS NOT NULL OR
NULLIF(Source.[my_table_last_updt_date], Target.[my_table_last_updt_date]) IS NOT NULL OR NULLIF(Target.[my_table_last_updt_date], Source.[my_table_last_updt_date]) IS NOT NULL OR
NULLIF(Source.[my_table_last_updt_time], Target.[my_table_last_updt_time]) IS NOT NULL OR NULLIF(Target.[my_table_last_updt_time], Source.[my_table_last_updt_time]) IS NOT NULL OR
NULLIF(Source.[my_table_last_updt_userid], Target.[my_table_last_updt_userid]) IS NOT NULL OR NULLIF(Target.[my_table_last_updt_userid], Source.[my_table_last_updt_userid]) IS NOT NULL OR
NULLIF(Source.[my_table_record_status], Target.[my_table_record_status]) IS NOT NULL OR NULLIF(Target.[my_table_record_status], Source.[my_table_record_status]) IS NOT NULL OR
NULLIF(Source.[my_table_name], Target.[my_table_name]) IS NOT NULL OR NULLIF(Target.[my_table_name], Source.[my_table_name]) IS NOT NULL OR
NULLIF(Source.[my_table_next_or_last_price], Target.[my_table_next_or_last_price]) IS NOT NULL OR NULLIF(Target.[my_table_next_or_last_price], Source.[my_table_next_or_last_price]) IS NOT NULL OR
NULLIF(Source.[my_table_pricing_frequency], Target.[my_table_pricing_frequency]) IS NOT NULL OR NULLIF(Target.[my_table_pricing_frequency], Source.[my_table_pricing_frequency]) IS NOT NULL OR
NULLIF(Source.[my_table_sell_pricing_frequency], Target.[my_table_sell_pricing_frequency]) IS NOT NULL OR NULLIF(Target.[my_table_sell_pricing_frequency], Source.[my_table_sell_pricing_frequency]) IS NOT NULL OR
NULLIF(Source.[my_table_commenced_date], Target.[my_table_commenced_date]) IS NOT NULL OR NULLIF(Target.[my_table_commenced_date], Source.[my_table_commenced_date]) IS NOT NULL OR
NULLIF(Source.[my_table_closed_date], Target.[my_table_closed_date]) IS NOT NULL OR NULLIF(Target.[my_table_closed_date], Source.[my_table_closed_date]) IS NOT NULL OR
NULLIF(Source.[my_table_closed_for_newbus_date], Target.[my_table_closed_for_newbus_date]) IS NOT NULL OR NULLIF(Target.[my_table_closed_for_newbus_date], Source.[my_table_closed_for_newbus_date]) IS NOT NULL OR
NULLIF(Source.[my_table_closed_for_spi_date], Target.[my_table_closed_for_spi_date]) IS NOT NULL OR NULLIF(Target.[my_table_closed_for_spi_date], Source.[my_table_closed_for_spi_date]) IS NOT NULL OR
NULLIF(Source.[my_table_closed_for_money_date], Target.[my_table_closed_for_money_date]) IS NOT NULL OR NULLIF(Target.[my_table_closed_for_money_date], Source.[my_table_closed_for_money_date]) IS NOT NULL OR
NULLIF(Source.[my_table_category], Target.[my_table_category]) IS NOT NULL OR NULLIF(Target.[my_table_category], Source.[my_table_category]) IS NOT NULL OR
NULLIF(Source.[my_table_spread_relationship], Target.[my_table_spread_relationship]) IS NOT NULL OR NULLIF(Target.[my_table_spread_relationship], Source.[my_table_spread_relationship]) IS NOT NULL OR
NULLIF(Source.[my_table_management_charge], Target.[my_table_management_charge]) IS NOT NULL OR NULLIF(Target.[my_table_management_charge], Source.[my_table_management_charge]) IS NOT NULL OR
NULLIF(Source.[my_table_sellout_period_mths], Target.[my_table_sellout_period_mths]) IS NOT NULL OR NULLIF(Target.[my_table_sellout_period_mths], Source.[my_table_sellout_period_mths]) IS NOT NULL OR
NULLIF(Source.[my_table_currency], Target.[my_table_currency]) IS NOT NULL OR NULLIF(Target.[my_table_currency], Source.[my_table_currency]) IS NOT NULL OR
NULLIF(Source.[my_table_price_tolerance], Target.[my_table_price_tolerance]) IS NOT NULL OR NULLIF(Target.[my_table_price_tolerance], Source.[my_table_price_tolerance]) IS NOT NULL OR
NULLIF(Source.[my_table_initial_price_date], Target.[my_table_initial_price_date]) IS NOT NULL OR NULLIF(Target.[my_table_initial_price_date], Source.[my_table_initial_price_date]) IS NOT NULL OR
NULLIF(Source.[my_table_last_date_in_period], Target.[my_table_last_date_in_period]) IS NOT NULL OR NULLIF(Target.[my_table_last_date_in_period], Source.[my_table_last_date_in_period]) IS NOT NULL OR
NULLIF(Source.[my_table_sell_last_date_in_period], Target.[my_table_sell_last_date_in_period]) IS NOT NULL OR NULLIF(Target.[my_table_sell_last_date_in_period], Source.[my_table_sell_last_date_in_period]) IS NOT NULL OR
NULLIF(Source.[my_table_last_day_in_period], Target.[my_table_last_day_in_period]) IS NOT NULL OR NULLIF(Target.[my_table_last_day_in_period], Source.[my_table_last_day_in_period]) IS NOT NULL OR
NULLIF(Source.[my_table_sell_last_day_in_period], Target.[my_table_sell_last_day_in_period]) IS NOT NULL OR NULLIF(Target.[my_table_sell_last_day_in_period], Source.[my_table_sell_last_day_in_period]) IS NOT NULL OR
NULLIF(Source.[my_table_same_day_in_period], Target.[my_table_same_day_in_period]) IS NOT NULL OR NULLIF(Target.[my_table_same_day_in_period], Source.[my_table_same_day_in_period]) IS NOT NULL OR
NULLIF(Source.[my_table_sell_same_day_in_period], Target.[my_table_sell_same_day_in_period]) IS NOT NULL OR NULLIF(Target.[my_table_sell_same_day_in_period], Source.[my_table_sell_same_day_in_period]) IS NOT NULL OR
NULLIF(Source.[my_table_use_working_days], Target.[my_table_use_working_days]) IS NOT NULL OR NULLIF(Target.[my_table_use_working_days], Source.[my_table_use_working_days]) IS NOT NULL OR
NULLIF(Source.[my_table_external_id], Target.[my_table_external_id]) IS NOT NULL OR NULLIF(Target.[my_table_external_id], Source.[my_table_external_id]) IS NOT NULL OR
NULLIF(Source.[my_table_post_initial_price_date], Target.[my_table_post_initial_price_date]) IS NOT NULL OR NULLIF(Target.[my_table_post_initial_price_date], Source.[my_table_post_initial_price_date]) IS NOT NULL OR
NULLIF(Source.[my_table_price_applies_frequency], Target.[my_table_price_applies_frequency]) IS NOT NULL OR NULLIF(Target.[my_table_price_applies_frequency], Source.[my_table_price_applies_frequency]) IS NOT NULL OR
NULLIF(Source.[my_table_price_country_code], Target.[my_table_price_country_code]) IS NOT NULL OR NULLIF(Target.[my_table_price_country_code], Source.[my_table_price_country_code]) IS NOT NULL OR
NULLIF(Source.[my_table_non_working_price_days_adj], Target.[my_table_non_working_price_days_adj]) IS NOT NULL OR NULLIF(Target.[my_table_non_working_price_days_adj], Source.[my_table_non_working_price_days_adj]) IS NOT NULL OR
NULLIF(Source.[my_table_pricing_calendar], Target.[my_table_pricing_calendar]) IS NOT NULL OR NULLIF(Target.[my_table_pricing_calendar], Source.[my_table_pricing_calendar]) IS NOT NULL OR
NULLIF(Source.[my_table_risk_profile], Target.[my_table_risk_profile]) IS NOT NULL OR NULLIF(Target.[my_table_risk_profile], Source.[my_table_risk_profile]) IS NOT NULL OR
NULLIF(Source.[my_table_pay_dividend], Target.[my_table_pay_dividend]) IS NOT NULL OR NULLIF(Target.[my_table_pay_dividend], Source.[my_table_pay_dividend]) IS NOT NULL OR
NULLIF(Source.[my_table_dividend_frequency], Target.[my_table_dividend_frequency]) IS NOT NULL OR NULLIF(Target.[my_table_dividend_frequency], Source.[my_table_dividend_frequency]) IS NOT NULL OR
NULLIF(Source.[my_table_sedol], Target.[my_table_sedol]) IS NOT NULL OR NULLIF(Target.[my_table_sedol], Source.[my_table_sedol]) IS NOT NULL OR
NULLIF(Source.[my_table_type], Target.[my_table_type]) IS NOT NULL OR NULLIF(Target.[my_table_type], Source.[my_table_type]) IS NOT NULL OR
NULLIF(Source.[my_table_strike_date], Target.[my_table_strike_date]) IS NOT NULL OR NULLIF(Target.[my_table_strike_date], Source.[my_table_strike_date]) IS NOT NULL OR
NULLIF(Source.[my_table_maturity_date], Target.[my_table_maturity_date]) IS NOT NULL OR NULLIF(Target.[my_table_maturity_date], Source.[my_table_maturity_date]) IS NOT NULL OR
NULLIF(Source.[my_table_amc_basis_no], Target.[my_table_amc_basis_no]) IS NOT NULL OR NULLIF(Target.[my_table_amc_basis_no], Source.[my_table_amc_basis_no]) IS NOT NULL OR
NULLIF(Source.[my_table_coupon_select_id], Target.[my_table_coupon_select_id]) IS NOT NULL OR NULLIF(Target.[my_table_coupon_select_id], Source.[my_table_coupon_select_id]) IS NOT NULL OR
NULLIF(Source.[my_table_coupon_defaults], Target.[my_table_coupon_defaults]) IS NOT NULL OR NULLIF(Target.[my_table_coupon_defaults], Source.[my_table_coupon_defaults]) IS NOT NULL OR
NULLIF(Source.[my_table_whole_units], Target.[my_table_whole_units]) IS NOT NULL OR NULLIF(Target.[my_table_whole_units], Source.[my_table_whole_units]) IS NOT NULL OR
NULLIF(Source.[my_table_clone_by_policy], Target.[my_table_clone_by_policy]) IS NOT NULL OR NULLIF(Target.[my_table_clone_by_policy], Source.[my_table_clone_by_policy]) IS NOT NULL OR
NULLIF(Source.[my_table_initial_clone_price], Target.[my_table_initial_clone_price]) IS NOT NULL OR NULLIF(Target.[my_table_initial_clone_price], Source.[my_table_initial_clone_price]) IS NOT NULL OR
NULLIF(Source.[my_table_price_base_calc_date], Target.[my_table_price_base_calc_date]) IS NOT NULL OR NULLIF(Target.[my_table_price_base_calc_date], Source.[my_table_price_base_calc_date]) IS NOT NULL OR
NULLIF(Source.[my_table_group], Target.[my_table_group]) IS NOT NULL OR NULLIF(Target.[my_table_group], Source.[my_table_group]) IS NOT NULL OR
NULLIF(Source.[my_table_disinv_notice_freq], Target.[my_table_disinv_notice_freq]) IS NOT NULL OR NULLIF(Target.[my_table_disinv_notice_freq], Source.[my_table_disinv_notice_freq]) IS NOT NULL OR
NULLIF(Source.[my_table_disinv_notice_value], Target.[my_table_disinv_notice_value]) IS NOT NULL OR NULLIF(Target.[my_table_disinv_notice_value], Source.[my_table_disinv_notice_value]) IS NOT NULL OR
NULLIF(Source.[my_table_disinv_same_day_in_period], Target.[my_table_disinv_same_day_in_period]) IS NOT NULL OR NULLIF(Target.[my_table_disinv_same_day_in_period], Source.[my_table_disinv_same_day_in_period]) IS NOT NULL OR
NULLIF(Source.[my_table_disinv_notice_last_date], Target.[my_table_disinv_notice_last_date]) IS NOT NULL OR NULLIF(Target.[my_table_disinv_notice_last_date], Source.[my_table_disinv_notice_last_date]) IS NOT NULL OR
NULLIF(Source.[my_table_trade_cutoff_freq], Target.[my_table_trade_cutoff_freq]) IS NOT NULL OR NULLIF(Target.[my_table_trade_cutoff_freq], Source.[my_table_trade_cutoff_freq]) IS NOT NULL OR
NULLIF(Source.[my_table_trade_cutoff_value], Target.[my_table_trade_cutoff_value]) IS NOT NULL OR NULLIF(Target.[my_table_trade_cutoff_value], Source.[my_table_trade_cutoff_value]) IS NOT NULL OR
NULLIF(Source.[my_table_trade_cutoff_same_day_in_period], Target.[my_table_trade_cutoff_same_day_in_period]) IS NOT NULL OR NULLIF(Target.[my_table_trade_cutoff_same_day_in_period], Source.[my_table_trade_cutoff_same_day_in_period]) IS NOT NULL OR
NULLIF(Source.[my_table_trade_cutoff_last_date], Target.[my_table_trade_cutoff_last_date]) IS NOT NULL OR NULLIF(Target.[my_table_trade_cutoff_last_date], Source.[my_table_trade_cutoff_last_date]) IS NOT NULL OR
NULLIF(Source.[my_table_expected_delay_rules], Target.[my_table_expected_delay_rules]) IS NOT NULL OR NULLIF(Target.[my_table_expected_delay_rules], Source.[my_table_expected_delay_rules]) IS NOT NULL OR
NULLIF(Source.[my_table_settlement_days], Target.[my_table_settlement_days]) IS NOT NULL OR NULLIF(Target.[my_table_settlement_days], Source.[my_table_settlement_days]) IS NOT NULL OR
NULLIF(Source.[my_table_bid_offer_exception_rules], Target.[my_table_bid_offer_exception_rules]) IS NOT NULL OR NULLIF(Target.[my_table_bid_offer_exception_rules], Source.[my_table_bid_offer_exception_rules]) IS NOT NULL OR
NULLIF(Source.[my_table_holding_fund_id], Target.[my_table_holding_fund_id]) IS NOT NULL OR NULLIF(Target.[my_table_holding_fund_id], Source.[my_table_holding_fund_id]) IS NOT NULL OR
NULLIF(Source.[my_table_timeout_days], Target.[my_table_timeout_days]) IS NOT NULL OR NULLIF(Target.[my_table_timeout_days], Source.[my_table_timeout_days]) IS NOT NULL OR
NULLIF(Source.[my_table_price_valuation_basis], Target.[my_table_price_valuation_basis]) IS NOT NULL OR NULLIF(Target.[my_table_price_valuation_basis], Source.[my_table_price_valuation_basis]) IS NOT NULL OR
NULLIF(Source.[my_table_classification], Target.[my_table_classification]) IS NOT NULL OR NULLIF(Target.[my_table_classification], Source.[my_table_classification]) IS NOT NULL OR
NULLIF(Source.[my_table_target_days], Target.[my_table_target_days]) IS NOT NULL OR NULLIF(Target.[my_table_target_days], Source.[my_table_target_days]) IS NOT NULL OR
NULLIF(Source.[my_table_sell_target_days], Target.[my_table_sell_target_days]) IS NOT NULL OR NULLIF(Target.[my_table_sell_target_days], Source.[my_table_sell_target_days]) IS NOT NULL OR
NULLIF(Source.[my_table_disinv_same_day_period_skip], Target.[my_table_disinv_same_day_period_skip]) IS NOT NULL OR NULLIF(Target.[my_table_disinv_same_day_period_skip], Source.[my_table_disinv_same_day_period_skip]) IS NOT NULL OR
NULLIF(Source.[my_table_trade_cutoff_same_day_period_skip], Target.[my_table_trade_cutoff_same_day_period_skip]) IS NOT NULL OR NULLIF(Target.[my_table_trade_cutoff_same_day_period_skip], Source.[my_table_trade_cutoff_same_day_period_skip]) IS NOT NULL OR
NULLIF(Source.[my_table_equity_sector], Target.[my_table_equity_sector]) IS NOT NULL OR NULLIF(Target.[my_table_equity_sector], Source.[my_table_equity_sector]) IS NOT NULL OR
NULLIF(Source.[my_table_client_classification], Target.[my_table_client_classification]) IS NOT NULL OR NULLIF(Target.[my_table_client_classification], Source.[my_table_client_classification]) IS NOT NULL OR
NULLIF(Source.[my_table_max_decimal_places], Target.[my_table_max_decimal_places]) IS NOT NULL OR NULLIF(Target.[my_table_max_decimal_places], Source.[my_table_max_decimal_places]) IS NOT NULL OR
NULLIF(Source.[my_table_rounding_method], Target.[my_table_rounding_method]) IS NOT NULL OR NULLIF(Target.[my_table_rounding_method], Source.[my_table_rounding_method]) IS NOT NULL OR
NULLIF(Source.[my_table_closing_time], Target.[my_table_closing_time]) IS NOT NULL OR NULLIF(Target.[my_table_closing_time], Source.[my_table_closing_time]) IS NOT NULL OR
NULLIF(Source.[my_table_rounding_direction], Target.[my_table_rounding_direction]) IS NOT NULL OR NULLIF(Target.[my_table_rounding_direction], Source.[my_table_rounding_direction]) IS NOT NULL OR
NULLIF(Source.[my_table_use_external_WS], Target.[my_table_use_external_WS]) IS NOT NULL OR NULLIF(Target.[my_table_use_external_WS], Source.[my_table_use_external_WS]) IS NOT NULL OR
NULLIF(Source.[my_table_gl_code], Target.[my_table_gl_code]) IS NOT NULL OR NULLIF(Target.[my_table_gl_code], Source.[my_table_gl_code]) IS NOT NULL OR
NULLIF(Source.[my_table_asset_class], Target.[my_table_asset_class]) IS NOT NULL OR NULLIF(Target.[my_table_asset_class], Source.[my_table_asset_class]) IS NOT NULL OR
NULLIF(Source.[my_table_grouping], Target.[my_table_grouping]) IS NOT NULL OR NULLIF(Target.[my_table_grouping], Source.[my_table_grouping]) IS NOT NULL OR
NULLIF(Source.[my_table_factsheet_url], Target.[my_table_factsheet_url]) IS NOT NULL OR NULLIF(Target.[my_table_factsheet_url], Source.[my_table_factsheet_url]) IS NOT NULL OR
NULLIF(Source.[my_table_aladdin_ticker], Target.[my_table_aladdin_ticker]) IS NOT NULL OR NULLIF(Target.[my_table_aladdin_ticker], Source.[my_table_aladdin_ticker]) IS NOT NULL OR
NULLIF(Source.[my_table_manager], Target.[my_table_manager]) IS NOT NULL OR NULLIF(Target.[my_table_manager], Source.[my_table_manager]) IS NOT NULL OR
NULLIF(Source.[my_table_use_notice_for_backdates], Target.[my_table_use_notice_for_backdates]) IS NOT NULL OR NULLIF(Target.[my_table_use_notice_for_backdates], Source.[my_table_use_notice_for_backdates]) IS NOT NULL OR
NULLIF(Source.[my_table_business_date_delay], Target.[my_table_business_date_delay]) IS NOT NULL OR NULLIF(Target.[my_table_business_date_delay], Source.[my_table_business_date_delay]) IS NOT NULL OR
NULLIF(Source.[my_table_growth_low], Target.[my_table_growth_low]) IS NOT NULL OR NULLIF(Target.[my_table_growth_low], Source.[my_table_growth_low]) IS NOT NULL OR
NULLIF(Source.[my_table_growth_med], Target.[my_table_growth_med]) IS NOT NULL OR NULLIF(Target.[my_table_growth_med], Source.[my_table_growth_med]) IS NOT NULL OR
NULLIF(Source.[my_table_growth_high], Target.[my_table_growth_high]) IS NOT NULL OR NULLIF(Target.[my_table_growth_high], Source.[my_table_growth_high]) IS NOT NULL OR
NULLIF(Source.[my_table_growth_SMPI], Target.[my_table_growth_SMPI]) IS NOT NULL OR NULLIF(Target.[my_table_growth_SMPI], Source.[my_table_growth_SMPI]) IS NOT NULL OR
NULLIF(Source.[my_table_instruction_file_decimal_places], Target.[my_table_instruction_file_decimal_places]) IS NOT NULL OR NULLIF(Target.[my_table_instruction_file_decimal_places], Source.[my_table_instruction_file_decimal_places]) IS NOT NULL OR
NULLIF(Source.[my_table_suspend_start_date], Target.[my_table_suspend_start_date]) IS NOT NULL OR NULLIF(Target.[my_table_suspend_start_date], Source.[my_table_suspend_start_date]) IS NOT NULL OR
NULLIF(Source.[my_table_suspend_end_date], Target.[my_table_suspend_end_date]) IS NOT NULL OR NULLIF(Target.[my_table_suspend_end_date], Source.[my_table_suspend_end_date]) IS NOT NULL ) THEN
UPDATE SET
[my_table_create_date] = Source.[my_table_create_date],
[my_table_last_updt_date] = Source.[my_table_last_updt_date],
-- All fields listed in order.
[my_table_suspend_end_date] = Source.[my_table_suspend_end_date]
WHEN NOT MATCHED BY TARGET THEN
INSERT([my_table_code],[my_table_create_date],[my_table_last_updt_date],[my_table_last_updt_time],[my_table_last_updt_userid],[my_table_record_status],[my_table_name],[my_table_next_or_last_price],[my_table_pricing_frequency],[my_table_sell_pricing_frequency],[my_table_commenced_date],[my_table_closed_date],[my_table_closed_for_newbus_date],[my_table_closed_for_spi_date],[my_table_closed_for_money_date],[my_table_category],[my_table_spread_relationship],[my_table_management_charge],[my_table_sellout_period_mths],[my_table_currency],[my_table_price_tolerance],[my_table_initial_price_date],[my_table_last_date_in_period],[my_table_sell_last_date_in_period],[my_table_last_day_in_period],[my_table_sell_last_day_in_period],[my_table_same_day_in_period],[my_table_sell_same_day_in_period],[my_table_use_working_days],[my_table_external_id],[my_table_post_initial_price_date],[my_table_price_applies_frequency],[my_table_price_country_code],[my_table_non_working_price_days_adj],[my_table_pricing_calendar],[my_table_risk_profile],[my_table_pay_dividend],[my_table_dividend_frequency],[my_table_sedol],[my_table_type],[my_table_strike_date],[my_table_maturity_date],[my_table_amc_basis_no],[my_table_coupon_select_id],[my_table_coupon_defaults],[my_table_whole_units],[my_table_clone_by_policy],[my_table_initial_clone_price],[my_table_price_base_calc_date],[my_table_group],[my_table_disinv_notice_freq],[my_table_disinv_notice_value],[my_table_disinv_same_day_in_period],[my_table_disinv_notice_last_date],[my_table_trade_cutoff_freq],[my_table_trade_cutoff_value],[my_table_trade_cutoff_same_day_in_period],[my_table_trade_cutoff_last_date],[my_table_expected_delay_rules],[my_table_settlement_days],[my_table_bid_offer_exception_rules],[my_table_holding_fund_id],[my_table_timeout_days],[my_table_price_valuation_basis],[my_table_classification],[my_table_target_days],[my_table_sell_target_days],[my_table_disinv_same_day_period_skip],[my_table_trade_cutoff_same_day_period_skip],[my_table_equity_sector],[my_table_client_classification],[my_table_max_decimal_places],[my_table_rounding_method],[my_table_closing_time],[my_table_rounding_direction],[my_table_use_external_WS],[my_table_gl_code],[my_table_asset_class],[my_table_grouping],[my_table_factsheet_url],[my_table_aladdin_ticker],[my_table_manager],[my_table_use_notice_for_backdates],[my_table_business_date_delay],[my_table_growth_low],[my_table_growth_med],[my_table_growth_high],[my_table_growth_SMPI],[my_table_instruction_file_decimal_places],[my_table_suspend_start_date],[my_table_suspend_end_date])
VALUES(Source.[my_table_code],Source.[my_table_create_date],Source.[my_table_last_updt_date],Source.[my_table_last_updt_time],Source.[my_table_last_updt_userid],Source.[my_table_record_status],Source.[my_table_name],Source.[my_table_next_or_last_price],Source.[my_table_pricing_frequency],Source.[my_table_sell_pricing_frequency],Source.[my_table_commenced_date],Source.[my_table_closed_date],Source.[my_table_closed_for_newbus_date],Source.[my_table_closed_for_spi_date],Source.[my_table_closed_for_money_date],Source.[my_table_category],Source.[my_table_spread_relationship],Source.[my_table_management_charge],Source.[my_table_sellout_period_mths],Source.[my_table_currency],Source.[my_table_price_tolerance],Source.[my_table_initial_price_date],Source.[my_table_last_date_in_period],Source.[my_table_sell_last_date_in_period],Source.[my_table_last_day_in_period],Source.[my_table_sell_last_day_in_period],Source.[my_table_same_day_in_period],Source.[my_table_sell_same_day_in_period],Source.[my_table_use_working_days],Source.[my_table_external_id],Source.[my_table_post_initial_price_date],Source.[my_table_price_applies_frequency],Source.[my_table_price_country_code],Source.[my_table_non_working_price_days_adj],Source.[my_table_pricing_calendar],Source.[my_table_risk_profile],Source.[my_table_pay_dividend],Source.[my_table_dividend_frequency],Source.[my_table_sedol],Source.[my_table_type],Source.[my_table_strike_date],Source.[my_table_maturity_date],Source.[my_table_amc_basis_no],Source.[my_table_coupon_select_id],Source.[my_table_coupon_defaults],Source.[my_table_whole_units],Source.[my_table_clone_by_policy],Source.[my_table_initial_clone_price],Source.[my_table_price_base_calc_date],Source.[my_table_group],Source.[my_table_disinv_notice_freq],Source.[my_table_disinv_notice_value],Source.[my_table_disinv_same_day_in_period],Source.[my_table_disinv_notice_last_date],Source.[my_table_trade_cutoff_freq],Source.[my_table_trade_cutoff_value],Source.[my_table_trade_cutoff_same_day_in_period],Source.[my_table_trade_cutoff_last_date],Source.[my_table_expected_delay_rules],Source.[my_table_settlement_days],Source.[my_table_bid_offer_exception_rules],Source.[my_table_holding_fund_id],Source.[my_table_timeout_days],Source.[my_table_price_valuation_basis],Source.[my_table_classification],Source.[my_table_target_days],Source.[my_table_sell_target_days],Source.[my_table_disinv_same_day_period_skip],Source.[my_table_trade_cutoff_same_day_period_skip],Source.[my_table_equity_sector],Source.[my_table_client_classification],Source.[my_table_max_decimal_places],Source.[my_table_rounding_method],Source.[my_table_closing_time],Source.[my_table_rounding_direction],Source.[my_table_use_external_WS],Source.[my_table_gl_code],Source.[my_table_asset_class],Source.[my_table_grouping],Source.[my_table_factsheet_url],Source.[my_table_aladdin_ticker],Source.[my_table_manager],Source.[my_table_use_notice_for_backdates],Source.[my_table_business_date_delay],Source.[my_table_growth_low],Source.[my_table_growth_med],Source.[my_table_growth_high],Source.[my_table_growth_SMPI],Source.[my_table_instruction_file_decimal_places],Source.[my_table_suspend_start_date],Source.[my_table_suspend_end_date])
WHEN NOT MATCHED BY SOURCE THEN
DELETE
;
GO
DECLARE #mergeError int
, #mergeCount int
SELECT #mergeError = ##ERROR, #mergeCount = ##ROWCOUNT
IF #mergeError != 0
BEGIN
PRINT 'ERROR OCCURRED IN MERGE FOR [my_table]. Rows affected: ' + CAST(#mergeCount AS VARCHAR(100)); -- SQL should always return zero rows affected
END
ELSE
BEGIN
PRINT '[my_table] rows affected by MERGE: ' + CAST(#mergeCount AS VARCHAR(100));
END
GO
EDIT: Ok so removing 2508 rows it works in seconds. I don't know enough about merge scripts to know why the amount of rows would affect this.
Inserting the values into a temp table first and referencing that in the merge fixed it.
Also, replacing the long list of NULLIF with:
WHEN MATCHED AND EXISTS
(
SELECT Source.*
EXCEPT
SELECT Target.*
)
worked to speed it up.

Compare between columns on different tables

I need to write T-SQL code that will compare between T1.PercentComplete that need to be between T2.StageFrom and T2.StageTo. and than get the T2.Bonus_Prec and join T1
T1:
T2:
The desired result for T2.Bonus_Prec is 0.02 since T1.Percent_Complete is .27, which is between 0 and 1.
The thing is that each Key can have a different T2.StageID between 1-6.
If Key have just one T2.StageID it'll be 0. (fast way for me to know that there is only 1 bonus option)
If it have more than 1 it's will start with 1. (This can be changed if needed)
T1:
DROP TABLE T1;
CREATE TABLE T1(
Key VARCHAR(10) NOT NULL PRIMARY KEY
,Percent_Complete_ NUMBER(16,2) NOT NULL
);
INSERT INTO T1(Key,Percent_Complete_) VALUES ('Key Vendor',Percent_Complete);
INSERT INTO T1(Key,Percent_Complete_) VALUES ('***',0.27);
T2:
DROP TABLE T2;
CREATE TABLE T2(
Key VARCHAR(50) NOT NULL
,StageID INT NOT NULL
,Stage_From NUMERIC(10,2) NOT NULL
,Stage_To NUMERIC(8,2) NOT NULL
,Stage_Bonus_Prec NUMERIC(16,2) NOT NULL
);
INSERT INTO T2(Key,StageID,Stage_From,Stage_To,Stage_Bonus_Prec) VALUES ('Key',Stage_Id,Stage_From,Stage_To,Stage_Bonus_Prec);
INSERT INTO T2(Key,StageID,Stage_From,Stage_To,Stage_Bonus_Prec) VALUES ('***',1,0,0.8,0.02);
INSERT INTO T2(Key,StageID,Stage_From,Stage_To,Stage_Bonus_Prec) VALUES ('***',2,0.8,1,0.035);
INSERT INTO T2(Key,StageID,Stage_From,Stage_To,Stage_Bonus_Prec) VALUES ('***',3,1,-1,0.05);
OUTPUT:
+-----+-------------------+--------------------+
| Key | Percent_Complete | [Stage_Bonus_Prec] |
+-----+-------------------+--------------------+
| *** | 0.27 | 0.02 |
+-----+-------------------+--------------------+
Here is a SQLFiddle with these values
It is still not clear what you are trying to do but I made an attempt. Please notice I also corrected a number of issues with ddl and sample data you posted.
if OBJECT_ID('T1') is not null
drop table T1
CREATE TABLE T1(
KeyVendor VARCHAR(10) NOT NULL PRIMARY KEY
,PercentComplete VARCHAR(16) NOT NULL
);
INSERT INTO T1(KeyVendor,PercentComplete) VALUES ('***','0.27');
if OBJECT_ID('T2') is not null
drop table T2
CREATE TABLE T2(
MyKey VARCHAR(50) NOT NULL
,StageID INT NOT NULL
,Stage_From NUMERIC(10,0) NOT NULL
,Stage_To NUMERIC(8,0) NOT NULL
,Stage_Bonus_Prec NUMERIC(16,3) NOT NULL
);
INSERT INTO T2(MyKey,StageID,Stage_From,Stage_To,Stage_Bonus_Prec) VALUES ('***',1,0,0.8,0.02);
INSERT INTO T2(MyKey,StageID,Stage_From,Stage_To,Stage_Bonus_Prec) VALUES ('***',2,0.8,1,0.035);
INSERT INTO T2(MyKey,StageID,Stage_From,Stage_To,Stage_Bonus_Prec) VALUES ('***',3,1,-1,0.05);
select *
from T1
cross apply
(
select top 1 Stage_Bonus_Prec
from T2
where t1.PercentComplete >= t2.Stage_Bonus_Prec
and t1.KeyVendor = t2.MyKey
order by Stage_Bonus_Prec
) x
Taking a shot at this as well, since it's still a bit unclear:
SELECT t1.percent_complete, t2.Stage_Bonus_Prec
FROM T1 INNER JOIN T2
ON T1.[key vendor] = T2.[Key] AND
T1.[percent_complete] BETWEEN T2.Stage_From AND T2.Stage_To
Joining T1 and T2 on [Key Vendor] and [Key] and using the BETWEEN operator to find the percent_complete value that is between Stage_From and Stage_To.
I think I'm still missing something since I'm still confused about where Key value of *** comes from in your desired results.
SQLFiddle of this in action, based on a slightly fixed up version of your DDL (you put your field names in their own data record, I've removed them since they don't belong there).

SQL Pivot on text columns returning multiple rows

I've been through a bunch of examples and other questions on SO, but I'm still having an issue with this pivot.
select [Address],[Address 1],[Address 2],[Address2],[Birth Day],[City],
[Email],[First Name],[Last Name],[Phone],[State],[Zip]
from
(SELECT *, row_number() over(PARTITION by formid order by formid) as rnk
FROM [Sitecore_WebForms].[dbo].[Field]
where FormId='C9681226-5951-403D-80A0-00019218785C'
) as SourceTable
pivot
(
max(value)
for [fieldname] in
([Address],[Address 1],[Address 2],[Address2],[Birth Day],[City],[Email],
[First Name],[Last Name],[Phone],[State],[Zip])
) as pt
The result comes back with 9 rows, 1 row for each column. How do I get it to combine these rows into a single row?
Address Address 1 Address 2 Address2 Birth Day City Email First Name Last Name Phone State Zip
NULL NULL NULL NULL NULL NULL NULL FIRS NULL NULL NULL NULL
NULL NULL NULL NULL NULL CITY NULL NULL NULL NULL NULL NULL
NULL NULL NULL NULL NULL NULL NULL NULL LAST NULL NULL NULL
NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL ZIP
ADDR NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL
NULL NULL NULL NULL DATE NULL NULL NULL NULL NULL NULL NULL
NULL NULL NULL NULL NULL NULL EMAI NULL NULL NULL NULL NULL
NULL NULL NULL NULL NULL NULL NULL NULL NULL PHON NULL NULL
NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL
source rows
Id FieldId FormId Value Data FieldName
CE160D15-EBCC-45B6-AB67-0CCA4AA081C7 09C0317E-E235-469D-AE7E-6CB9C45916EA C9681226-5951-403D-80A0-00019218785C FIRS First Name
393E6220-8CC8-4B4E-A75B-29E1801A9A65 2ED6CAC8-7210-4BBC-9497-3B0E8A5F7CF7 C9681226-5951-403D-80A0-00019218785C LAST Last Name
64F9A694-406E-4385-932E-2D0D68A17FB7 FA5C1C21-CCFC-4E96-A1D8-57AC7B1AEF2C C9681226-5951-403D-80A0-00019218785C ADDR Address
960A2BB5-0B50-4640-8EC8-170677809E64 CA9184AE-99CD-46C0-A72D-47FBD4F768AB C9681226-5951-403D-80A0-00019218785C CITY City
CD954912-B24A-4726-9729-2ACD6DDD00C9 E695546B-2BBA-4AFF-9DAF-1B5666E42C74 C9681226-5951-403D-80A0-00019218785C ZIP Zip
FD19C907-F779-4CF8-90B7-4E072CDE36BE DF056320-27BD-4E15-BF73-AC0C4A1CF543 C9681226-5951-403D-80A0-00019218785C DATE Birth Day
497AC034-6686-4023-ADE9-CB825F65DBFE 06807268-1689-4DDF-BDE2-08FBA31E56AE C9681226-5951-403D-80A0-00019218785C PHON Phone
8A438C22-9C8E-4759-998F-542917408E38 D9402E5E-09CE-40E6-86F7-D80D99417208 C9681226-5951-403D-80A0-00019218785C EMAI Email
If we only select value and filedName from Source it will work as expected.
select [Address],[Address 1],[Address 2],[Address2],[Birth Day],[City],
[Email],[First Name],[Last Name],[Phone],[State],[Zip]
from
(SELECT value, fieldname
FROM [Sitecore_WebForms].[dbo].[Field]
where FormId='C9681226-5951-403D-80A0-00019218785C'
) as SourceTable
pivot
(
max(value)
for [fieldname] in
([Address],[Address 1],[Address 2],[Address2],[Birth Day],[City],[Email],
[First Name],[Last Name],[Phone],[State],[Zip])
) as pt
Update for all the forms:
DECLARE #form TABLE
(
id INT,
formid INT,
fieldName VARCHAR(32),
fieldValue VARCHAR(32)
)
insert into #form values(1,1,'First Name','FRST')
insert into #form values(2,1,'Last Name','LST')
insert into #form values(3,1,'Address','ADDR')
insert into #form values(4,2,'First Name','FRST2')
insert into #form values(5,2,'Last Name','LST2')
insert into #form values(6,2,'Address','ADDR2')
select FormId,[Address],[Address 1],[Address 2],[Address2],[Birth Day],[City],
[Email],[First Name],[Last Name],[Phone],[State],[Zip]
from
(SELECT FormId,fieldName,fieldValue
FROM #form
--where FormId=1
) as SourceTable
pivot
(
max(fieldValue)
for [fieldname] in
([Address],[Address 1],[Address 2],[Address2],[Birth Day],[City],[Email],
[First Name],[Last Name],[Phone],[State],[Zip])
) as pt
PIVOT will only "rotate" the columns you list; any other columns will still occopy their own row. In your case, both Id and FieldId will cause each row to remain.
To solve that, exclude those columns in a subquery:
select *
from (
select FormId
, Value
, FieldName
from #t
) as SourceTable
pivot (
max(value)
for FieldName in
(Address,[Address 1],[Address 2],Address2,...)
) as PivotAlias;
Working example at SE DATA.

How come the only value ever entered in the SQL Server field is 0?

I have two tables csvtemp and leads in both tables i have a is_download field and i am moving data from one table to another
First i insert into the csvtemp table with this
CREATE TABLE CSVTemp
(id INT,
firstname VARCHAR(255),
lastname VARCHAR(255),
department VARCHAR(255),
architecture VARCHAR(255),
phone VARCHAR(255),
email VARCHAR(255),
download VARCHAR(255),
comments VARCHAR(MAX),
company VARCHAR(255),
location VARCHAR(255),
is_download VARCHAR(255)
)
GO
BULK
INSERT CSVTemp
FROM 'c:\leads\leads.csv'
WITH
(
DATAFILETYPE = 'char',
BATCHSIZE = 50,
FIELDTERMINATOR = ',',
ROWTERMINATOR = '\n'
)
GO
--Check the content of the table.
SELECT *
FROM CSVTemp
GO
i then checked the csvtemp table and here is my data so far
id,firstname,lastname,department,architecture,phone,email,download,comments,company,location,is_download
258,sdf,ssss,NULL,NULL,951-5566,kate#gmail.com,"Aldelo for Restaurants","I am just looking right now. When I get ready to purchasing I will contact you.","my Diner","Aldelo for Restaurants demo download",1
274,Scott,Henry,sales,NULL,485-755-7439,aerf99#comcast.net,NULL,"Need a POS cash registering system that can help us.","The Attak","Contact Us: Contact Form",0
275,Test,Tstt,NULL,NULL,8566778888,test#test.com,"Aldelo for Restaurants",testing,Staction,"Aldelo for Restaurants demo download",1
so far so good the 1 and 0 is being entered in the is_download field as expected but when i do this next stell to move it from csvtemp to the leads table its 0
INSERT INTO [SalesLogix].[sysdba].[LEAD] (
LEADID,
ASSIGNDATE,
COMPANY_UC,
EMAIL,
ISDOWNLOAD,
WORKPHONE)
SELECT
'Q' + cast(floor(999997 * RAND(convert(varbinary, newid()))) as varchar(20)) + cast(floor(999 * RAND(convert(varbinary, newid()))) as varchar(20))
,CURRENT_TIMESTAMP
,replace(UPPER(company), '"', '')
,replace(email, '"', '')
,is_download
,replace(phone, '"', '')
FROM [SalesLogix].[sysdba].[CSVTemp]
everything else inserts fine but the is_download is always 0
BTW the ISDOWNLOAD in the leads table is varchar (80)
UPDATE...
here are some records in the leads table...i could not get the three froom earlier because they were deleted but here is what all look like the ISDOWNLOAD is 0
LEADID CREATEUSER CREATEDATE MODIFYUSER MODIFYDATE ACCOUNTMANAGERID ASSIGNDATE BUSINESSDESCRIPTION COMPANY COMPANY_UC CREDITRATING DATAQUALITY DESCRIPTION DIVISION DONOTSOLICIT EMAIL EMPLOYEES FAX FIRSTNAME HOMEPHONE IMPORTID IMPORTSOURCE INDUSTRY INTERESTS ISPRIMARY LASTCALLDATE LASTNAME LASTNAME_UC LEADSOURCEID MIDDLENAME MOBILE NEXTCALLDATE NOTES PREFERRED_CONTACT PREFIX PRIORITY QUALIFICATION_CATEGORYID REVENUE SECCODEID SICCODE STATUS SUFFIX TICKER TITLE TOLLFREE TYPE ISDOWNLOAD USERFIELD2 USERFIELD3 USERFIELD4 USERFIELD5 USERFIELD6 USERFIELD7 USERFIELD8 USERFIELD9 USERFIELD10 WEBADDRESS WORKPHONE LEAD_ADDRESSID DONOTEMAIL DONOTFAX DONOTMAIL DONOTPHONE
Q102842996 U6UJ9A00000S 36:10.1 U6UJ9A00000G 31:27.0 U6UJ9A00000G 36:10.1 NULL Lunch Money LUNCH MONEY NULL NULL NULL NULL 0 shane.hubbell#gmail.com NULL NULL Shane NULL NULL NULL sales Contact Us: Contact Form T NULL Hubbell HUBBELL L6UJ9A000004 NULL NULL NULL Interested in your software more than your hardware. Please email first and well setup some time to chat. NULL NULL NULL NULL NULL SYST00000001 NULL New NULL NULL NULL NULL NULL 0 NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL 5185705656 QQ102842996 NULL NULL NULL NULL
Q103999935 U6UJ9A00000S 06:10.2 U6UJ9A00000E 53:43.0 U6UJ9A00000E 06:10.2 NULL Alajamy ALAJAMY NULL NULL NULL NULL 0 sfgsd#hotmail.fr NULL NULL Nizar NULL NULL NULL NULL Aldelo for Restaurants demo download T NULL Ben Ali BEN ALI L6UJ9A000002 NULL NULL NULL NULL NULL NULL NULL NULL NULL SYST00000001 NULL Follow-up NULL NULL NULL NULL NULL 0 NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL QQ103999935 NULL NULL NULL NULL
Q109565345 U6UJ9A00000S 36:10.1 U6UJ9A00000G 00:20.0 NULL 36:10.1 NULL NULL NULL NULL NULL NULL NULL 0 NULL NULL NULL NULL NULL NULL NULL NULL NULL T NULL NULL NULL L6UJ9A000004 NULL NULL NULL NULL NULL NULL NULL NULL NULL SYST00000001 NULL Purge NULL NULL NULL NULL NULL 0 NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL QQ109565345 NULL NULL NULL NULL
Q11143312 U6UJ9A00000S 06:10.1 U6UJ9A00000G 10:27.0 U6UJ9A00000G 06:10.1 NULL Noobs NOOBS NULL NULL NULL NULL 0 fdfgsd#gmail.com NULL NULL Eduardo NULL NULL NULL NULL Aldelo for Restaurants demo download T NULL Torres TORRES L6UJ9A000004 NULL NULL NULL NULL NULL NULL NULL NULL NULL SYST00000001 NULL New NULL NULL NULL NULL NULL 0 NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL QQ11143312 NULL NULL NULL NULL
ANOTHER EDIT after running SELECT '$$' + is_download + '$$' FROM CSVTemp
$$1 $$
$$0 $$
$$1 $$
Using only the code you posted and an insert statement to replace the BULK INSERT (which does not seem to be the problem), I am able to create rows in CSVTemp that translate correctly to the LEAD table.
Something else must be going on. Check to make sure the LEAD table doesn't have any triggers on it.