2017-08-24 156 views
-1

我想从CSV文件中加载SQL Server表。批量插入CSV文件的问题

我BULK INSERT语句:

bulk insert ClassList from 'ClassList.csv' 
with (
    firstrow=2, 
    fieldterminator=',', 
    maxerrors=100, 
    keepnulls 
    ); 

大部分数据加载,但不是少数行,其中的一个字段包含一个逗号,使他们有双引号的分隔符 - 在这里排21 & 23载,但不是22 :

21,Blue or Lilac Smoke Adult,22,PER, 
22,"Red, Tortie, Cream, Blue or Lilac Cream or Choc. Tortie Smoke Adult",23,PER, 
23,AC Silver Tabby Adult,24,PER, 

我的表:

Class_Number varchar(10) not null 
Class_Description varchar(200) not null 
Class_Order int not null 
Section_ID varchar(10) not null 
Judge_Initials varchar(10) null 

使用S SMS v17.2。

SQL服务器的详细信息:

Product Version:   13.0.4206.0 
Product Name:    SQL Server 2016 
Product Level:   SP1 
Product Edition:   Express Edition (64-bit) 

回答

0

确定答案在上面发布的链接是,在我的版本的软件的批量加载不能有一些周围的报价文件处理 - 类似的问题,在下面的链接回答领域。我没有试过看是否引用了所有的字符字段。我resaved作为制表符分隔的字段(.txt),它已经加载得很好。

从MS文档:

https://docs.microsoft.com/en-us/sql/t-sql/statements/bulk-insert-transact-sql

**Input file format options** 
FORMAT = 'CSV' 
Applies to: SQL Server 2017 CTP 1.1. 
Specifies a comma separated values file compliant to the RFC 4180 standard. 

FIELDQUOTE = 'field_quote' 
Applies to: SQL Server 2017 CTP 1.1. 
Specifies a character that will be used as the quote character in the CSV 
file. If not specified, the quote character (") will be used as the quote 
character as defined in the RFC 4180 standard. 

格式选项是不能接受这也许是我的问题的根源。