【问题标题】:Conversion failed when converting date and/or time from character string error message从字符串错误消息转换日期和/或时间时转换失败
【发布时间】:2013-07-24 12:01:14
【问题描述】:

这是在 SSMS 中

我正在尝试插入以下虚拟测试语句及其失败

INSERT INTO Client 
(
     [name], 
     [address], 
     [DOB], 
     [Mobile], 
     [Email], 
     [profession], 
     [refby]
)
VALUES 
(
     'Toby Keith', 
     '8 big dog daddy lane oklahoma 40518', 
     '28/06/2010', 
     '0424 280 185', 
     'tk@hotmail.com', 
     'Country Superstar', 
     'Willie'
)

我得到的信息是:

Msg 241, Level 16, State 1, Line 2
Conversion failed when converting date and/or time from character string.

现在我已经使用了很多次了,没有任何问题,我错过了什么愚蠢的小东西?

【问题讨论】:

  • 您是否像往常一样使用同一用户运行查询?还是您更改了语言设置?
  • 天哪,我是个白痴,我没有设置日期时间格式,而是使用 int 作为手机号码而不是 nvarchar!对不起大家浪费你的时间

标签: sql-server sql-insert


【解决方案1】:

使用ISO日期时间格式-

INSERT INTO Client 
(
     [name], 
     [address], 
     [DOB], 
     [Mobile], 
     [Email], 
     [profession], 
     [refby]
)
VALUES 
(
     'Toby Keith', 
     '8 big dog daddy lane oklahoma 40518', 
     '20100628', 
     '0424 280 185', 
     'tk@hotmail.com', 
     'Country Superstar', 
     'Willie'
)

【讨论】:

    猜你喜欢
    • 2016-08-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-04-17
    • 2017-12-07
    相关资源
    最近更新 更多