Forum Discussion
Ian-209
Nov 08, 2023Copper Contributor
Can I BULK INSERT a column > 8000 chars?
Howdy! I've scoured the internet on this but am coming up blank - so apologies if this has already been asked.. I've been asked to import a .csv where one of the columns exceeds 8,000 chars....
olafhelper
Nov 09, 2023Bronze Contributor
Ian-209 wrote:but it looks like this method doesn't work.
Ian-209 , "doesn't work" means what in details? Error?
An alternative is a SSIS package with data flow; which uses BULK INSERT behind the scene.
- Ian-209Nov 09, 2023Copper Contributor
hi olafhelper!
Here's the error I hit..
BULK INSERT <table_name>
FROM 'file.csv'
WITH
(
FORMAT='CSV',
FIRSTROW=2,
FIELDQUOTE = '"'
)->
Msg 4863, Level 16, State 1, Server <server_name>, Line 3
Bulk load data conversion error (truncation) for row 2, column 10 (<column_name>)...but if I were to manually edit the .csv and remove a few chars from the .csv to bring the column data < 8,000 chars then it works fine.
The column type is a VARCHAR(MAX) but I'm guessing that BULK INSERT is using a native VARCHAR datatype..
I.
- Ian-209Nov 09, 2023Copper ContributorI figured it out! I was BULK INSERTING into a VIEW (because I had some DEFAULT values that weren't included in the .csv). Switching to BULK INSERT into a table worked.