我正在尝试从csv文件加载数据并继续收到这些错误。我是否在批量插入脚本中遗漏了一些参数,或者在尝试此操作之前是否需要修改文件?
Msg 4866, Level 16, State 1, Line 1
The bulk load failed. The column is too long in the data file for row 1, column 54. Verify that the field terminator and row terminator are specified correctly.
Msg 7399, Level 16, State 1, Line 1
The OLE DB provider "BULK" for linked server "(null)" reported an error. The provider did not give any information about the error.
Msg 7330, Level 16, State 2, Line 1
Cannot fetch a row from OLE DB provider "BULK" for linked server "(null)".
这是脚本
BULK
INSERT BrowseNotes
FROM 'C:\Users\Jarek\browseNotes2.csv'
WITH
(
FIELDTERMINATOR = ','
, ROWTERMINATOR = '\n'
)
以下是文件中的示例行,我在尝试加载之前删除了第一行。行以“,/ n”结尾。我已经尝试用/ r / n替换/ n并删除最后一个逗号。仍然得到相同的错误。
LoanType,Maturity,LoanClass,Borrower,LoanStatus,TimeLeftBeforeExpiration,MonthlyPayment,LoanMaturity,JobTenureYearsString,AmountToInvest,AmountMissingToClose,NumberOfPayments,Id,State,Type,Status,Aid,Amount,Duration,StartD,IntRate,Grade,Purpose,HousingStatus,JobTenure,Income,CreditClassId,City,UnfundedAmnt,Fico,OpenCreditLines,TotalCreditLines,Inq6Months,RevolvUtil,FundedPercentage,FundedAmount,EmpStatus,JobTitle,AppDate,AppAmount,Employer,DelinquentAmount,EarliestCreditLine,PubRecords,DTI,AppExpiration,LapStatus,IncomeVStatus,CreditReportD,RevolvCreditBal,AccntsNowDelinquent,Delinquencies2Yrs,MnthsSinceLastDelinquency,MnthsSinceLastRecord
PERSONAL,60,C4,1248804,INFUNDING,279589,344.62,Year5,8 years,0,625.0,60,1020047,PA,1,1,1248804,13775.0,60,2011-11-11 11:40:18,0.1527,C,debt_consolidation,MORTGAGE,96,50000.0,124,PHILADELPHIA,625.0,679-713,10,21,2,62.2,0.9565972222222222,13775.0,EMPLOYED,"Quality Assurance Manager",2011-11-11 11:40:18,14400.0,"J. Ambrogi Food Distribution",0.0,01/27/2003,0,23.14,2011-11-25 11:40:18,APPROVED_CR,NOT_REQUIRED,11/11/2011,22906.0,0,0,null,null,
PERSONAL,60,A5,1247389,INFUNDING,180323,289.94,Year5,3 years,0,1975.0,60,1018925,FL,1,1,1247389,12025.0,60,2011-11-10 08:05:52,0.089,A,house,MORTGAGE,36,150000.0,105,orange park,1950.0,750-779,9,25,0,62.9,0.8607142857142858,12050.0,EMPLOYED,"Project Manager",2011-11-10 08:05:52,14000.0,"Scientific Research Corp.",0.0,10/01/1984,0,14.02,2011-11-24 08:05:52,APPROVED_CR,VERIFIED,11/09/2011,43069.0,0,0,null,null,
这是我正在尝试加载到
的表格CREATE TABLE [dbo].[BrowseNotes](
[LoanType] [nvarchar](25) NULL,
[Maturity] [tinyint] NULL,
[LoanClass] [nvarchar](2) NULL,
[Borrower] [int] NULL,
[LoanStatus] [nvarchar](25) NULL,
[TimeLeftBeforeExpiration] [int] NULL,
[MonthlyPayment] [smallmoney] NULL,
[LoanMaturity] [nvarchar](10) NULL,
[JobTenureYearsString] [nvarchar](15) NULL,
[AmountToInvest] [smallmoney] NULL,
[AmountMissingToClose] [smallmoney] NULL,
[NumberOfPayments] [tinyint] NULL,
[Id] [int] NULL,
[State] [char](2) NULL,
[Type] [tinyint] NULL,
[Status] [tinyint] NULL,
[Aid] [int] NULL,
[Amount] [smallmoney] NULL,
[Duration] [tinyint] NULL,
[StartD] [datetime] NULL,
[IntRate] [decimal](18, 0) NULL,
[Grade] [char](1) NULL,
[Purpose] [nvarchar](25) NULL,
[HousingStatus] [nvarchar](25) NULL,
[JobTenure] [tinyint] NULL,
[Income] [money] NULL,
[CreditClassId] [smallint] NULL,
[City] [nvarchar](255) NULL,
[UnfundedAmnt] [smallmoney] NULL,
[Fico] [nvarchar](10) NULL,
[OpenCreditLines] [tinyint] NULL,
[TotalCreditLines] [tinyint] NULL,
[Inq6Months] [tinyint] NULL,
[RevolvUtil] [decimal](18, 0) NULL,
[FundedPercentage] [decimal](18, 0) NULL,
[FundedAmount] [smallmoney] NULL,
[EmpStatus] [nvarchar](25) NULL,
[JobTitle] [nvarchar](255) NULL,
[AppDate] [datetime] NULL,
[AppAmount] [money] NULL,
[Employer] [nvarchar](255) NULL,
[DelinquentAmount] [money] NULL,
[EarliestCreditLine] [datetime] NULL,
[PubRecords] [tinyint] NULL,
[DTI] [decimal](18, 0) NULL,
[AppExpiration] [datetime] NULL,
[LapStatus] [nvarchar](25) NULL,
[IncomeVStatus] [nvarchar](25) NULL,
[CreditReportD] [datetime] NULL,
[RevolvCreditBal] [money] NULL,
[AccntsNowDelinquent] [tinyint] NULL,
[Delinquencies2Yrs] [tinyint] NULL,
[MnthsSinceLastDelinquency] [nvarchar](10) NULL,
[MnthsSinceLastRecord] [nvarchar](10) NULL
)
答案 0 :(得分:1)
该表中的数据库是什么?尝试完全限定您的表名,即
`mydb.dbo.BrowseNotes`
虽然听起来肯定不会认出ROWTERMINATOR。
答案 1 :(得分:1)
我知道这件事迟到了,但我想出了怎么做。
DECLARE @sql varchar(1000)
set @sql = '
BULK
INSERT BrowseNotes
FROM "C:\Users\Jarek\browseNotes2.csv"
WITH (
FIELDTERMINATOR = ",",
ROWTERMINATOR = "' + char(10) + '"
)'
exec(@sql)
GO
此脚本的工作方式是将rowterminator强制为文字' 0A' (换行)。这适用于\ r \ n和\ n终止数据。
我还建议使用管道字符(或数据中包含的任何不)作为字段终止符。 BULK INSERT
对数据中的嵌入字段终止符不是很宽容。
此外,在语句中添加FIRSTROW
不会跳过第一行的字段验证。因此,您必须在导入前删除标题,而不是跳过它们。