Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Importing CSV to SQL Server with text column > 8000 characters

I'm trying to import a csv file with two columns (sku, description) into SQL Server 2008 using the SQL Server management studio 2012 import/export wizard. Because the description column definitely has rows greater than 8000 characters, I go to the advanced tab when choosing the csv data source and click on the description column and click "Suggest Types". It then puts in 16718 for the OutPutColumnWidth property. Apparently there is a description in there somewhere that is THAT long.

The sql it generates is:

CREATE TABLE [dbo].[mag-prod-descriptions1] (
[sku] varchar(7),
[descrip] varchar(16718)
)

However, when I execute the import, I get the error "Could not connect source component. Error 0xc0204016: SSIS.Pipeline: The "Source - mag-prod-descriptions1_csv.Outputs[Flat File Source Output].Columns[Column 1]" has a length that is not valid. The length must be between 0 and 8000."

If I change the OutputColumnWidth property to 8000 then I get an error saying the column was truncated. I can't win.

How do I get the thing to allow me to import cells that are greater than 8000 characters?

like image 415
Michelle Williamson Avatar asked Sep 19 '13 16:09

Michelle Williamson


People also ask

How do I add more than 8000 characters in SQL?

Remember, whenever you are planning to insert more than 8000 characters to any varchar column, you must cast it as varchar(max) before insertion.

How does CSV handle commas in SQL?

The best, quickest and easiest way to resolve the comma in data issue is to use Excel to save a comma separated file after having set Windows' list separator setting to something other than a comma (such as a pipe). This will then generate a pipe (or whatever) separated file for you that you can then import.


1 Answers

Ack. Finally got it. The answer was to use the Text Stream datatype for the large column on the source file.

like image 94
Michelle Williamson Avatar answered Nov 07 '22 19:11

Michelle Williamson