1
嘗試在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
你的文件是否有標題?它可能是它試圖讀取標題並將其插入浮動列。根據Microsoft的 –
FIRSTROW屬性不打算跳過列標題。跳過標題不受BULK INSERT語句支持。在跳過行時,SQL Server數據庫引擎只會查看字段終止符,並且不會驗證跳過行的字段中的數據。 –
我把表中的所有內容都切換到了一個varchar,並且解決了float問題,但現在它正在抱怨最後一列Total_Losses – HDB