SQL Server 插入日期为 1/1/1900 [英] SQL Server inserting Date as 1/1/1900

查看:50
本文介绍了SQL Server 插入日期为 1/1/1900的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 ASP 经典页面在表中插入记录.我正在为 5 个字段使用表单元素,即.[ABC] ([code], [updatedate], [flag], [Mfdate].当用户没有选择 Mdate 时,使用日期控件获取用户在 Mdate 中选择的日期,它在我的 ASP 中形成的查询页面如下

I am having ASP Classic page to insert record in table. I am using form element for 5 fields viz. [ABC] ([code], [updatedate], [flag], [Mfdate]. And using the date control to get user selected date in Mdate when user does not select the Mdate, the query that it is getting formed in my ASP page is as below

INSERT INTO [ABC] ([code], [updatedate], [flag], [Mfdate]) 
VALUES('203 ', '6/12/2013', 'N/A', '')

当它在 SQL Server 中运行时,它为 Mfdate 插入日期 1/1/1900 但用户没有选择任何值.

When it is run in SQL Server it is inserting date 1/1/1900 for Mfdate but User has not selected any value.

为什么会这样?

Mfdate 的数据类型是 datetime.

推荐答案

您没有将其指定为 null,您正试图插入一个空字符串 ('').您需要:

You have not given it as null, you're trying to insert an empty string (''). You need:

INSERT INTO [ABC] ([code],[updatedate],[flag],[Mfdate]) 
VALUES ('203', '6/12/2013','N/A', NULL) 

尽管实际上,如果您要插入日期,最好以 YYYYMMDD 格式插入它们,例如:

Although really, if you're going to be inserting dates, best to insert them in YYYYMMDD format, as:

INSERT INTO [ABC] ([code],[updatedate],[flag],[Mfdate]) 
VALUES ('203', '20130612','N/A', NULL) 

这篇关于SQL Server 插入日期为 1/1/1900的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆