从 varchar 数据类型到 datetime 数据类型的转换产生一个超出范围的值。

SQL2008 R2. 表结构如下

create table MITARBEITER (
ID int not null primary key,
ABT_ID char(2) not null references Abteilung(id),
NAME char(25) not null,
VORNAME char(25) not null,
GEBURTSDATUM datetime null,
GESCHLECHT char(1) null,
GEHALT money null,
ORT char(25) null,
PLZ char(6) null,
STRASSE char(30) null,
BILD image null
)
出错的insert语句如下:

insert into mitarbeiter values (10102,'a3','Huber','Petra', '14.5.1985','W',3000.0,'Varel',26316,'Hafenweg 3b',null);
神奇的是。。。这句是没错的:
insert into mitarbeiter values (25348,'a3','Keller','Hans', '3.2.1980','M',3400.0,'Jade',26349,'Jader Strasse 32',null);

求大神求解

你用字符串表示日期,最大的问题是系统默认的日期格式是什么?

综合你的描述:
这个是错的,'14.5.1985'
这个是对的,'3.2.1980'
估计你的系统默认的格式是: m.d.yyyy

建议:
1. 转成日期再插入
insert into mitarbeiter values (10102,'a3','Huber','Petra', convert(datetime,'1985-05-14 00:00:00',120),'W',3000.0,'Varel',26316,'Hafenweg 3b',null);
如果必须用你自己那个格式'14.5.1985',你自己找一下。

2. 或者:明确一下默认的日期格式。
温馨提示:答案为网友推荐,仅供参考

相关了解……

你可能感兴趣的内容

本站内容来自于网友发表,不代表本站立场,仅表示其个人看法,不对其真实性、正确性、有效性作任何的担保
相关事宜请发邮件给我们
© 非常风气网