I have a CSV File with 17 columns, where one column [CustName) has various customer names and some of them have commas.
Example "ABC Company, Inc"
I want to Bulk Insert the CSV file into a table.
The command is:
BULK INSERT [dbo].vPTInsert
FROM '\\Server\GROUP-Data\AfftonImports\Invoice_Detail_Export_Report 2-28-20.csv'
WITH ( FIRSTROW = 2,
FIELDTERMINATOR = ',',
ROWTERMINATOR = '\n' ,
FORMATFILE = '\\Server\GROUP-Data\AfftonImports\Format.fmt')
I get the error:
Cannot bulk load. Invalid column number in the format file
The format file:
11.0
21
1 SQLCHAR 0 20 "," 1 InvNum QL_Latin1_General_CP1_CI_AS
2 SQLCHAR 0 10 "," 2 InvType QL_Latin1_General_CP1_CI_AS
3 SQLCHAR 0 30 "," 3 BolNum QL_Latin1_General_CP1_CI_AS
4 SQLCHAR 0 40 "," 4 PONum QL_Latin1_General_CP1_CI_AS
5 SQLCHAR 0 11 "\r\n" 5 InvDate QL_Latin1_General_CP1_CI_AS
6 SQLCHAR 0 15 "," 6 BatchNum QL_Latin1_General_CP1_CI_AS
7 SQLCHAR 0 60 "," 7 CustName QL_Latin1_General_CP1_CI_AS
8 SQLCHAR 0 10 "," 8 Company QL_Latin1_General_CP1_CI_AS
9 SQLCHAR 0 10 "," 9 Terminal QL_Latin1_General_CP1_CI_AS
10 SQLCHAR 0 20 "," 10 InvAmt QL_Latin1_General_CP1_CI_AS
11 SQLCHAR 0 11 "\r\n" 11 GLDate QL_Latin1_General_CP1_CI_AS
12 SQLCHAR 0 20 "," 12 Header_Detail QL_Latin1_General_CP1_CI_AS
13 SQLCHAR 0 50 "," 13 ChargeCode QL_Latin1_General_CP1_CI_AS
14 SQLCHAR 0 50 "," 14 GLAccount QL_Latin1_General_CP1_CI_AS
15 SQLCHAR 0 20 "," 15 DebitAmt QL_Latin1_General_CP1_CI_AS
16 SQLCHAR 0 20 "," 16 CreditAmt QL_Latin1_General_CP1_CI_AS
17 SQLCHAR 0 200 "," 17 Memo QL_Latin1_General_CP1_CI_AS
side note: The column headings (Row 1) of the CSV file do not exactly match the column names in the destination table.
The Format File column names are from the the Table, not the CSV file.
So for example Column 7 in the CSV File is labled 'custnumb' but the table is 'CustName'
Not sure that matters given I have FIRSTROW = 2 in the Bulk Insert command.
Thanks,
Chuck
Example "ABC Company, Inc"
I want to Bulk Insert the CSV file into a table.
The command is:
BULK INSERT [dbo].vPTInsert
FROM '\\Server\GROUP-Data\AfftonImports\Invoice_Detail_Export_Report 2-28-20.csv'
WITH ( FIRSTROW = 2,
FIELDTERMINATOR = ',',
ROWTERMINATOR = '\n' ,
FORMATFILE = '\\Server\GROUP-Data\AfftonImports\Format.fmt')
I get the error:
Cannot bulk load. Invalid column number in the format file
The format file:
11.0
21
1 SQLCHAR 0 20 "," 1 InvNum QL_Latin1_General_CP1_CI_AS
2 SQLCHAR 0 10 "," 2 InvType QL_Latin1_General_CP1_CI_AS
3 SQLCHAR 0 30 "," 3 BolNum QL_Latin1_General_CP1_CI_AS
4 SQLCHAR 0 40 "," 4 PONum QL_Latin1_General_CP1_CI_AS
5 SQLCHAR 0 11 "\r\n" 5 InvDate QL_Latin1_General_CP1_CI_AS
6 SQLCHAR 0 15 "," 6 BatchNum QL_Latin1_General_CP1_CI_AS
7 SQLCHAR 0 60 "," 7 CustName QL_Latin1_General_CP1_CI_AS
8 SQLCHAR 0 10 "," 8 Company QL_Latin1_General_CP1_CI_AS
9 SQLCHAR 0 10 "," 9 Terminal QL_Latin1_General_CP1_CI_AS
10 SQLCHAR 0 20 "," 10 InvAmt QL_Latin1_General_CP1_CI_AS
11 SQLCHAR 0 11 "\r\n" 11 GLDate QL_Latin1_General_CP1_CI_AS
12 SQLCHAR 0 20 "," 12 Header_Detail QL_Latin1_General_CP1_CI_AS
13 SQLCHAR 0 50 "," 13 ChargeCode QL_Latin1_General_CP1_CI_AS
14 SQLCHAR 0 50 "," 14 GLAccount QL_Latin1_General_CP1_CI_AS
15 SQLCHAR 0 20 "," 15 DebitAmt QL_Latin1_General_CP1_CI_AS
16 SQLCHAR 0 20 "," 16 CreditAmt QL_Latin1_General_CP1_CI_AS
17 SQLCHAR 0 200 "," 17 Memo QL_Latin1_General_CP1_CI_AS
side note: The column headings (Row 1) of the CSV file do not exactly match the column names in the destination table.
The Format File column names are from the the Table, not the CSV file.
So for example Column 7 in the CSV File is labled 'custnumb' but the table is 'CustName'
Not sure that matters given I have FIRSTROW = 2 in the Bulk Insert command.
Thanks,
Chuck