date类型null值默认成1900-1-1
我的数据库,插入数据,date类型的,我想插入空值,但他默认会变为1900-1-1,有什么方法可以显示为空值吗?
[解决办法]
if OBJECT_ID('tb') is not null drop table tb
go
create table tb(id int,dd date)
insert into tb(id,dd)
select 1,'2013-09-26' union all
select 2,null
go
select * from tb
go
drop table tb
go
/**
(2 行受影响)
id dd
----------- ----------
1 2013-09-26
2 NULL
(2 行受影响)
*/
select dd2=(case dd when '1900-01-01' then '' else dd end) from tb
create table [tb]([id] INT ,[times] datetime DEFAULT null)
insert [tb]
select 1,'2013-09-26'
对比下ID=2和ID=3的,看看你的需求
if OBJECT_ID('tb') is not null drop table tb
go
create table tb(id int,dd datetime default null)
insert into tb(id,dd)
select 1,'2013-09-26' union all
select 2,'' union all
select 3,null
go
select * from tb
go
drop table tb
go
/**
id dd
----------- -----------------------
1 2013-09-26 00:00:00.000
2 1900-01-01 00:00:00.000
3 NULL
(3 行受影响)
*/