SQL Server not importing data to table

0

I'm using SQL Server 2008 R2, I'm creating the following table and then trying to import the data by right clicking on the database name -> task -> import data. While going through the import settings I'm assigning the corresponding data types in the column settings. I have reviewed the source file and do not see anything that sticks out that would be causing errors in the import process. I have included the errors that I'm receiving under the table script.

Any thoughts on the errors? Or why I can not import the data from the table?

Thank you!

CREATE TABLE customer
(
id integer NOT NULL PRIMARY KEY,
username varchar(128) NOT NULL,
email_address varchar(128) NOT NULL,
date_of_birth date NOT NULL,
different_mailing_address bit,
employment_status varchar(255),
first_name varchar(128) NOT NULL,
last_name varchar(128) NOT NULL,
middle_name varchar(128),
gender varchar(255),
months_at_current_address integer,
months_at_current_employment integer,
months_at_previous_address integer,
mothers_maiden_name varchar(255) NOT NULL,
cellular_phone_number varchar(255),
daytime_phone_number varchar(255),
evening_phone_number varchar(255),
home_phone_number varchar(255),
work_phone_number varchar(255),
social_security_number varchar(255) NOT NULL,
special_employer_group varchar(255),
stated_lead_source  varchar(255),
stated_lead_source_desc varchar(255),
us_citizenship_status varchar(255),
us_non_immigrant_classification varchar(255),
us_tax_residency varchar(255),
existing_customer bit,
existing_customer_number varchar(255),
credit_report_fk integer,
current_home_address_fk integer,
expense_fk integer,
family_info_fk integer,
housing_info_fk integer,
id_verification_fk integer,
income_fk integer,
mailing_address_fk integer,
previous_employment_fk integer,
previous_home_address_fk integer,
primary_employment_fk integer,
worksheet_fk integer,
linked_dda_fk integer,
portfolio_id varchar(255),
portfolio_line_number varchar(255),
created datetime,
last_update datetime
)

Messages

Error 0xc02020a1: Data Flow Task 1: Data conversion failed. The data conversion for column "Column 0" returned status value 2 and status text "The value could not be converted because of a potential loss of data.".

Error 0xc0209029: Data Flow Task 1: SSIS Error Code DTS_E_INDUCEDTRANSFORMFAILUREONERROR. The "output column "Column 0" (10)" failed because error code 0xC0209084 occurred, and the error row disposition on "output column "Column 0" (10)" specifies failure on error. An error occurred on the specified object of the specified component. There may be error messages posted before this with more information about the failure.

Error 0xc0202092: Data Flow Task 1: An error occurred while processing file "Y:\ANDERA\customer.csv" on data row 1.

Error 0xc0047038: Data Flow Task 1: SSIS Error Code DTS_E_PRIMEOUTPUTFAILED. The PrimeOutput method on component "Source - customer_csv" (1) returned error code 0xC0202092. The component returned a failure code when the pipeline engine called PrimeOutput(). The meaning of the failure code is defined by the component, but the error is fatal and the pipeline stopped executing. There may be error messages posted before this with more information about the failure.

sql
database
sql-server-2008-r2
sqldatatypes
data-import
asked on Stack Overflow Mar 20, 2015 by SEANDON • edited Mar 20, 2015 by marc_s

2 Answers

0

it could be useful, for more effective help, to view some test line of your csv. I try..

I see in your SQL script several constraints that can generate error using this import function (many particular dataType). For this reason you have to review well your csv. Remember that when your import from csv there are always conversions between some strings to a particular data type in SQL, so you have to be sure the string is formatted well for conversion.. First of all you have to control the data and datetime fields. Is it written in a way that SQL can successfully convert? Then, there are many NOT NULL fields, are they correctly populated in your CSV ? are the integer fields on your CSV real integer number (like 1 , 2 not 1.0 etc).

If you plan to do this task once, what about if you import your data in a table as simple as possibile (more varchar(255) fields as possibile), after that you could have the possibilty in SQL server to cast/convert all the fields in your wanted data type, and then with the statement (SELECT INTO), you could copy that data in the your complex table. In this way you could test better where are problems.

answered on Stack Overflow Mar 20, 2015 by Antonio Bruno • edited Mar 21, 2015 by Antonio Bruno
0

It sounds like your truncating data because of converting from one datatype to another. Look at your CSV data. The text might be longer than you're giving it or there might be decimal values in one of those fields. It sounds like it might be the second one.

You can try to find the offending field by splitting the file up and importing it piece by piece until you find the row causing the error.

answered on Stack Overflow Mar 20, 2015 by Shawn

User contributions licensed under CC BY-SA 3.0