简体   繁体   English

将数据类型varchar转换为数字时出错-但具有数字值

[英]Error converting data type varchar to numeric - but with numeric value

I have the following table in SQL Server 2014: 我在SQL Server 2014中具有下表:

effDate  DATETIME(23) NOT NULL  
rateType CHAR(2) NOT NULL  
rate     DECIMAL(10, 8) NOT NULL  

When I run the following query, I get an error message: 当我运行以下查询时,我收到一条错误消息:

Select Failed: 8114 Error converting data type varchar to numeric. 选择失败:8114将数据类型varchar转换为数字时出错。

My query: 我的查询:

insert into hprs.dbo.OHPRSrates 
values ('01/01/2019', 'D', 0.02642000)

Why? 为什么? The only numeric column in this row is rate and the insert value is clearly numeric 该行中唯一的数字列是rate ,插入值显然是数字

I suspect those columns are not in the order you believe they are in. When inserting, you should really declare the columns you're inserting into. 怀疑这些列的排列顺序不符合您所相信的顺序。插入时,您应该真正声明要插入的列。 Does this, by any chance, work? 这有什么用吗?

INSERT INTO hprs.dbo.OHPRSrates (effDate,rateType,rate)
VALUES ('01/01/2019','D',0.02642000);

Also, however, I would recommend using a unambiguous date format, such as yyyyMMdd . 另外,但是,我建议使用明确的日期格式,例如yyyyMMdd Thus, for your date, '20190101' . 因此,对于您的日期,请输入'20190101' A value of 01/01/2019 is 01 January what ever way you read it, however, is 01/02/2019 02 January or 01 February? 值的01/01/2019 01/02/2019 1月01日,而您阅读的方式是01/02/2019是1月02日还是2月01日? The answer depends on your language (settings). 答案取决于您的语言(设置)。

try this 尝试这个

insert into hprs.dbo.OHPRSrates 
(effDate, rateType, rate) values ('01/01/2019','D',0.02642000)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM