How to easily import a .csv file into an existing table in SSMS?

Copper Contributor

Hi, I have a bunch of .csv files (one for each day of logs) that I want to import into a table.

My issue is that I am having a very hard time with creating the table in the first place.

Half of the content of the .csv files is in Japanese, this might be related to the problem. When importing a .csv file using both the wizards in the program, the automatic data type detection does not work. I had to work around it by making a table adding everything as text and using a query to get the max length of the all the columns and apply it to creating a new table. Next, I also have problems with things such as cannot convert string to type nvarchar, etc. The thing that bugs me with this is I have a lot of columns and if I try and it doesn't work, it tends to reset some times and I have to re-do everything, taking ridiculously long.

 

However, I have made the table for one file before. 

So I was thinking the easiest way would simply be to import all the csv files directly into the table I already made. Using the wizard, however, I get the below problem:

I open the Import Data wizard, and select my source flat file. It displays correctly in the preview.

I select my destination table, the table I already made before that is working with correct data types.

Every item is green except for one yellow triangle at a column called customer acc number. 

I run it, it fails:

 

Messages
Error 0xc02020a1: Data Flow Task 1: Data conversion failed. The data conversion for column " Hold_at" returned status value 2 and status text "The value could not be converted because of a potential loss of data.".
(SQL Server Import and Export Wizard)

Error 0xc0209029: Data Flow Task 1: SSIS Error Code DTS_E_INDUCEDTRANSFORMFAILUREONERROR. The "Source - 0618_csv.Outputs[Flat File Source Output].Columns[ Hold_at]" failed because error code 0xC0209084 occurred, and the error row disposition on "Source - 0618_csv.Outputs[Flat File Source Output].Columns[ Hold_at]" 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.
(SQL Server Import and Export Wizard)

Error 0xc0202092: Data Flow Task 1: An error occurred while processing file "C:\Users\xxxxx\Desktop\Log\TODO\0618.csv" on data row 2.
(SQL Server Import and Export Wizard)

Error 0xc0047038: Data Flow Task 1: SSIS Error Code DTS_E_PRIMEOUTPUTFAILED. The PrimeOutput method on Source - 0618_csv 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 Server Import and Export Wizard)

I know this might be a hard case to solve without a lot of additional information, so I'd rather ask this:

 

Is there no simple way to just import a set of data into a table with the same columns?

Say, I use the data for May 1st as a template and make a May 1st table.

I rename May 1st table to 'tbLogs'.

From May 2nd and onwards, I just import the data into tbLogs instead of creating new tables.

The data types should all be the same and it should go hand in hand just fine.

 

Is the above not possible?

Thank you!

0 Replies