SQL Server: Varchar to Numeric Conversion Error - No Numeric -


i encountering data-conversion error on table-insert , baffled. i'm writing script quick-and-dirty reconciliation of freight costs pre-consolidation , post-consolidation databases. have 2 db tables created importing csv files. keep things simple dba, data csv files go varchar columns in tables - recon scripts handle conversion/casting needed. client on sql server 2008 r2.

here abbreviated definitions tables in question:

create table [dbo].[nocommit_prod]( [sort_delta_total] [varchar](50) null, [rec_type] [varchar](50) null, [price_id] [varchar](50) null, [quote_id] [varchar](50) null, [shipto_org_id] [varchar](50) null, ... [trace] [varchar](8000) null ) on [primary]   create table [dbo].[nocommit_test]( [sort_delta_total] [varchar](50) null, [rec_type] [varchar](50) null, [price_id] [varchar](50) null, [quote_id] [varchar](50) null, [shipto_org_id] [varchar](50) null, ... [trace] [varchar](8000) null ) on [primary] 

here temp-table definition , insert/select statement that's erroring:

if object_id('tempdb..#tmp1') not null drop table #tmp1 create table #tmp1( price_id bigint ,quote_id bigint ,shipto_id bigint ,product_id bigint ,trmnl_id bigint ,carrier_id bigint ,test_freight_pricing_rt decimal(15,7) ,prod_freight_pricing_rt decimal(15,7) ,test_trace varchar(8000) ,prod_trace varchar(8000) ,test_carrierid_found bigint ,prod_carrierid_found bigint ,test_surcharge  decimal(15,7) ,prod_surcharge  decimal(15,7) ,test_xtra_surcharge  decimal(15,7) ,prod_xtra_surcharge  decimal(15,7) ,test_miles int ,prod_miles int ,test_rate decimal(15,7) ,prod_rate decimal(15,7) ,explanation varchar(400) )  insert #tmp1( price_id ,quote_id ,shipto_id ,product_id ,trmnl_id ,carrier_id ,test_freight_pricing_rt ,prod_freight_pricing_rt ,test_trace ,prod_trace ) select cast(p.price_id bigint) ,cast(p.quote_id bigint) ,cast(p.shipto_org_id bigint) ,cast(q.product_id bigint) ,cast(p.cust_term_relation_id bigint) ,cast(p.carrier_org_id bigint) ,cast(t.freight decimal(15,7)) ,cast(p.freight decimal(15,7)) ,t.trace ,p.trace nocommit_prod p join nocommit_test t on p.price_id = t.price_id join tbl_fuel_cost_quote q on q.quote_id = p.quote_id join tbl_fuel_cust_price cp on cp.price_id = p.price_id p.price_id != 'null' , p.price_id <> -1 

when execute above, returns "msg 8114, level 16, state 5, line 54 error converting data type varchar numeric.". if comment out insert of prod_trace column, executes fine. i'm baffled this, since source prod_trace nocommit_prod.trace columns (same size , type). cannot find wrong source data. can please provide insight on why i'm getting error when there no numeric involved?

thanks , insight can furnish!!

yes, execute following script:

  declare @t table (col1 decimal(10,2));    insert @t (col1) values ('hi'); 

and error message:

msg 8114, level 16, state 5, line 3 error converting data type varchar numeric.

the error lies in data in 1 of decimal columns.


Comments

Popular posts from this blog

Fail to load namespace Spring Security http://www.springframework.org/security/tags -

sql - MySQL query optimization using coalesce -

unity3d - Unity local avoidance in user created world -