我有一个数据集,我想将其导入到sql表中。 一小部分数据样本如下:
Ticker,BloombergID,Sedol,RICCode,Cusip,UnderDescription,Description,CountryOfIssuer,CountryOfIssue,Industry,Sector,MarketValue,NotionalExposure,ImpliedVolatility,Delta,DeltaAdjExp,Gamma,Rho,Theta,Vega,ExchangeContractCode,ExpiryDate,CallPut,StrikePrice,Price,SaxoSymbolCode,FixedSaxoSymbolCode,ExpiryDateFixed
1JY78U5,,,1JY78U5,99A0TT759,JAPANESE YEN SEP15 FUTURE CME,JAPANESE YEN SEP15 PUT @ 0.78 EXP 09/04/2015,United States,United States,Specialized Finance,Financials,3975,625574.99,0.1,-0.16,,4.17,0,0,0,j1,9/4/2015,0,0.78,0.01,6J/U15P0.01:xcme ,6J/U15P0.78:xcme,20150904
1JY755U5,,,1JY755U5,99A16JKW0,JAPANESE YEN SEP15 FUTURE CME,JAPANESE YEN SEP15 PUT @ 0.755 EXP 09/04/2015,United States,United States,Specialized Finance,Financials,1012.5,312787.49,0.11,-0.09,,2.53,0,0,0,j1,9/4/2015,0,0.755,0,6J/U15P0.01:xcme ,6J/U15P0.755:xcme,20150904
1JY765U5,,,1JY765U5,99A0YZT71,JAPANESE YEN SEP15 FUTURE CME,JAPANESE YEN SEP15 PUT @ 0.765 EXP 09/04/2015,United States,United States,Specialized Finance,Financials,-450,-104262.5,0.11,-0.12,,3.13,0,0,0,j1,9/4/2015,0,0.765,0,6J/U15P0.01:xcme ,6J/U15P0.765:xcme,20150904
最后一列计算为
=VALUE(YEAR(ExpiryDate)&IF(MONTH(ExpiryDate)<10,0&MONTH(ExpiryDate),MONTH(ExpiryDate))&IF(DAY(ExpiryDate)<10,0&DAY(ExpiryDate),DAY(ExpiryDate)))`
使用Excel,然后将其保存为CSV(逗号分隔)文件。 (而不是分号分隔)
我使用
创建一个SQL表USE [RiskMart]
GO
/****** Object: Table [meta].[ETOGreeks20150320] Script Date: 3/23/2015 4:47:07 PM ******/
DROP TABLE [meta].[ETOGreeks20150320]
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
CREATE TABLE [meta].[ETOGreeks20150320](
[Ticker] [varchar](255) NULL,
[BloombergID] [varchar](255) NULL,
[Sedol] [varchar](255) NULL,
[RICCode] [varchar](255) NULL,
[Cusip] [varchar](255) NULL,
[UnderDescription] [varchar](255) NULL,
[Description] [varchar](255) NULL,
[CountryOfIssuer] [varchar](255) NULL,
[CountryOfIssue] [varchar](255) NULL,
[Industry] [varchar](255) NULL,
[Sector] [varchar](255) NULL,
[MarketValue] [float] NULL,
[NotionalExposure] [float] NULL,
[ImpliedVolatility] [float] NULL,
[Delta] [float] NULL,
[DeltaAdjExp] [float] NULL,
[Gamma] [float] NULL,
[Rho] [float] NULL,
[Theta] [float] NULL,
[Vega] [float] NULL,
[ExchangeContractCode] [varchar](255) NULL,
[ExpiryDate] [datetime] NULL,
[CallPut] [bit] NULL,
[StrikePrice] [float] NULL,
[Price] [float] NULL,
[SaxoSymbolCode] [varchar](255) NULL,
[FixedSaxoSymbolCode] [varchar](255) NULL,
[ExpiryDateFixed] [int] NULL,
) ON [PRIMARY]
GO
SET ANSI_PADDING OFF
GO
当我使用批量插入
时BULK
INSERT RiskMart.meta.ETOGreeks20150320
FROM '\\path\ETO Greeks.csv'
WITH
(
FIELDTERMINATOR = ',',
ROWTERMINATOR = '\n'
)
我收到以下错误:
Msg 4864,Level 16,State 1,Line 9批量加载数据转换错误 (为指定的代码页键入不匹配或无效字符) 第1行第28列(ExpiryDateFixed)。
我试图将最后一列的数据类型更改为varchar(255),但这只会给我一条新的错误消息:
Msg 4863,Level 16,State 1,Line 9批量加载数据转换错误 (截断)第1行第28列(ExpiryDateFixed)。
我真的不知道该怎么做。 你能帮我吗?
P.S。我创建列的原因&#34; ExpiryDateFixed&#34;是因为&#34; ExpiryDate&#34; column是一个excel日期时间值,但当我尝试将其作为&#34; smalldatetime&#34; -column导入SQL时,它将1900-1-1作为日期返回。
其他信息: 我使用的是带有Windows 7,Excel专业2010,SQL Server 2012和SQL Server 2014的PC, 我在2014年创建了该表,并使用2012进行批量插入。我已经使用了这个设置半年,并没有遇到任何问题。