将CSV文件导入SQLServer我正在找人帮我进口.csv使用BULK INSERT我也没有什么基本的问题。问题:CSV文件数据可能有,(逗号)中间(Ex:Description),那么如何使导入处理这些数据?如果客户端从Excel创建CSV,则带有逗号的数据包含在""(双引号)(如下例所示)那么导入如何处理这个问题呢?如何跟踪某些行是否有错误的数据,哪些导入跳过?(导入是否跳过不可输入的行)下面是带有标头的示例CSV:Name,Class,Subject,ExamDate,Mark,Description
Prabhat,4,Math,2/10/2013,25,Test data for prabhat.Murari,5,Science,2/11/2013,24,"Test data for his's test, where we can test 2nd ROW,
Test."sanjay,4,Science,,25,Test Only.和要导入的SQL语句:BULK INSERT SchoolsTempFROM 'C:\CSVData\Schools.csv'WITH(
FIRSTROW = 2,
FIELDTERMINATOR = ',', --CSV field delimiter
ROWTERMINATOR = '\n', --Use to shift the control to next row
TABLOCK)
3 回答
慕莱坞森
TA贡献1810条经验 获得超4个赞
Tasks -> Import Data...
Next >
Flat File Source
Next >
Use SQL Server Authentication
Next >
Next >
Run immediately
Next >
Finish
BIG阳
TA贡献1859条经验 获得超6个赞
2)如果客户端从excel创建CSV,则有逗号的数据包含在“.”中。(双引号)(如下例所示)那么导入如何处理这个问题呢?
BULK INSERT SchoolsTempFROM 'C:\CSVData\Schools.csv'WITH( FORMAT = 'CSV', FIELDQUOTE = '"', FIRSTROW = 2, FIELDTERMINATOR = ',', --CSV field delimiter ROWTERMINATOR = '\n', --Use to shift the control to next row TABLOCK)
添加回答
举报
0/150
提交
取消