April 1, 2016 at 1:34 pm
I have this file as below
'A',
'B',
'C',
I am using this bulk insert below:
BULK INSERT test..A FROM 'c:\test.txt'
WITH (
DATAFILETYPE='char',
FIELDTERMINATOR='","',
ROWTERMINATOR = '')
But I am still getting 'A', in the table:
In the table I want
A
B
C
April 1, 2016 at 1:57 pm
You need to use a format file to identify the quotes as part of your delimiter. BCP won't remove the quotes for you otherwise.
April 1, 2016 at 2:14 pm
Luis Cazares (4/1/2016)
You need to use a format file to identify the quotes as part of your delimiter. BCP won't remove the quotes for you otherwise.
Or run an UPDATE query after importing, if you don't mind the overhead of hitting the table twice rather than once.
The absence of evidence is not evidence of absence
- Martin Rees
The absence of consumable DDL, sample data and desired results is, however, evidence of the absence of my response
- Phil Parkin
April 1, 2016 at 8:09 pm
PJ_SQL (4/1/2016)
I have this file as below'A',
'B',
'C',
I am using this bulk insert below:
BULK INSERT test..A FROM 'c:\test.txt'
WITH (
DATAFILETYPE='char',
FIELDTERMINATOR='","',
ROWTERMINATOR = '')
But I am still getting 'A', in the table:
In the table I want
A
B
C
Part of the problem is that you have a linefeed as a row terminator in addition to the comma. Luiz is mostly correct though because the actual delimiter is quote comma cr quote where cr is representative of whatever row terminator that you have. That does nothing for the leading quote nor the final quote comma.
Or, just use BCP/Bulk Insert to import the data as is an post process the data in a single pass update to remove the extraneous characters.
--Jeff Moden
Change is inevitable... Change for the better is not.
April 4, 2016 at 6:49 am
Phil Parkin (4/1/2016)
Luis Cazares (4/1/2016)
You need to use a format file to identify the quotes as part of your delimiter. BCP won't remove the quotes for you otherwise.Or run an UPDATE query after importing, if you don't mind the overhead of hitting the table twice rather than once.
And there's the issue on having to increase the columns' lenght by two to prevent truncation errors. In a staging table, of course.
Viewing 5 posts - 1 through 4 (of 4 total)
You must be logged in to reply to this topic. Login to reply