日期:2014-05-18  浏览次数:20763 次

datetime空值时的问题
create   table   D_plan
  (
    landmark_id     int   primary   key,
    AA_date   datetime,
    BB_date   datetime,
  );

insert   into   D_plan   values(1, ' ', ' ');

select   *   from   D_plan   时

出现
1,1900-01-01   00:00:00.000,1900-01-01   00:00:00.000

如何让1900-01-01   00:00:00.000,1900-01-01   00:00:00.000不出现;


------解决方案--------------------
datetime 默认值就为这个,LZ可以先定义成字符型,用到时转成DATETIME型
------解决方案--------------------
取出时强制转换一下就行了
select landmark_id,case when AA_date= '1900-01-01 00:00:00.000 ' then ' ' end AA_date,case when BB_date= '1900-01-01 00:00:00.000 ' then ' ' end BB_date from D_plan 时
------解决方案--------------------
insert into D_plan values(1,NULL,NULL);
------解决方案--------------------
create table D_plan
(
landmark_id int primary key,
AA_date datetime,
BB_date datetime,
);

insert into D_plan values(1,NULL,NULL);

select * from D_plan

--result
landmark_id AA_date BB_date
----------- ------------------------------------------------------ ------------------------------------------------------
1 NULL NULL

(1 row(s) affected)
------解决方案--------------------
select landmark_id,convert(varchar,AA_date,111) AA_date,convert(varchar,BB_date,111) AA_date from D_plan
------解决方案--------------------
insert into D_plan values(1, ' ', ' ')


============>

insert into D_plan values(1,null,null)


--------------------
' '转化成datetime型就变成1900-01-01 00:00:00.000
------解决方案--------------------
1900-01-01 00:00:00.000这个是SQL默认的就少时间,如果没有指定年份的情况下