Forum Discussion
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. I'm using BULK INSERT (I've attempted other methods) but it looks like this method doesn't work. Manually cutting down the column data < 8,000 works, just to see, works fine. The final column datatype is a VARCHAR(MAX) but I'm assuming the INSERT BULK is limited to a regular VARCHAR of 8,000..?
Does anyone have any alternatives? I'm not able to change the source .csv so my options are limited.
I.
4 Replies
- olafhelperBronze Contributor
- Ian-209Copper 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-209Copper 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.
- Ian-209Copper ContributorTo add - the string is enclosed by quotes (not all the strings in the .csv are) and it includes commas.