尝试在SQL 2014 Express中进行批量插入但收到错误。似乎进程在上传到的表的第一个浮点值上失败。
我正在使用excel office 2013并使用“,”分隔符另存为CSV。 在处理之前已经删除了带有“_”的逗号 在处理之前将我的文件扩展名更改为txt
错误:
Msg 4864, Level 16, State 1, Line 1
Bulk load data conversion error (type mismatch or invalid character for the specified codepage) for row 2, column 7 (NEW_PARTS_TERM).
示例导入文件是:
ID,DEALER_NUM,DEALER_NAME,NEW_WARRANTY_SKU_NUM,NEW_WARRANTY_SKU_NAME,NEW_PARTS_TERM,EARNING_TYPE,PROGRAM_TYPE,PURCHDT,FAILDT,CLAIMCNT,TOTAL_LOSSES
1,1060,Officemax,189400,OM 2YR ADH PREM SVC $450-$549.99 P,24.00,U,SERVICE,4/1/2015,8/1/2015,1.00,341.16
2,1060,Officemax,189400,OM 2YR ADH PREM SVC $450-$549.99 P,24.00,U,SERVICE,4/1/2015,9/1/2015,1.00,181.16
*执行存储过程*
Exec [dbo].[BulkInsertFiles] 'Losses', 'C:\Users\hb\Desktop\FileUpload\', 'AllCNA_LossesDataThru_Aug-2016_Purch.txt'
*存储过程代码*
ALTER PROCEDURE [dbo].[BulkInsertFiles]
-- Add the parameters for the stored procedure here
@INDEX nvarchar(20),
@PATH nvarchar(100),
@FILENAME nvarchar(50)
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
-- Varaibles
DECLARE @FULLPath nvarchar(MAX)
DECLARE @QUERY nvarchar(MAX)
-- Insert statements for procedure here
SET @FULLPATH = '''' + @Path + @FILENAME +''''
SET @QUERY = 'BULK INSERT ' + @Index +
' FROM' + @FULLPATH + ' WITH
(
FIRSTROW = 2,
FIELDTERMINATOR = '','',
ROWTERMINATOR = '''',
TABLOCK
)';
--Print @query;
EXEC(@query);
END
*表架构*
CREATE TABLE [dbo].[Losses](
[ID] [int] IDENTITY(1,1) NOT NULL,
[DEALER_NUM] [nvarchar](200) NULL,
[DEALER_NAME] [nvarchar](200) NULL,
[UNDERWRITER] [nvarchar](50) NULL,
[NEW_WARRANTY_SKU_NUM] [nvarchar](200) NULL,
[NEW_WARRANTY_SKU_NAME] [nvarchar](200) NULL,
[NEW_PARTS_TERM] [float] NULL,
[EARNING_TYPE] [nvarchar](50) NULL,
[PROGRAM_TYPE] [nvarchar](200) NULL,
[PURCHDT] [date] NULL,
[FAILDT] [date] NULL,
[CLAIMCNT] [float] NULL,
[TOTAL_LOSSES] [float] NULL,
PRIMARY KEY CLUSTERED
(
[ID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
答案 0 :(得分:0)
表和数据中的字段数问题,我匹配它们并修复了我的数据。
不需要删除标题。