2017-08-24 116 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. 

格式選項是不能接受這也許是我的問題的根源。