# 日期有关问题 - 应该算简单吧(2)

www.myexceptions.net  网友分享于：2013-01-27  浏览：5次

------解决方案--------------------

insert @TA
select 1,'R','2007-8-25',null,0 union all
select 2,'F','2007-8-2',null,0 union all
select 3,'F','2007-8-26',null,0 union all
select 4,'F','2007-8-19',null,0 union all
select 5,'R','2007-8-19',null,0 union all
select 6,'R','2007-8-1',null,0

update @TA
end

update @TA
SET MyEndDate=CASE WHEN datepart(weekday,Adate)=1 THEN '' ELSE MyEndDate END,
MySign=case when datepart(weekday,Adate)=1 then 1 else 0 end

SELECT * FROM @TA

----------- ------ ------------------------------------------------------ ------------------------------------------------------ -----------
1 R 2007-08-25 00:00:00.000 2007-08-26 00:00:00.000 0
2 F 2007-08-02 00:00:00.000 2007-08-19 00:00:00.000 0
3 F 2007-08-26 00:00:00.000 1900-01-01 00:00:00.000 1
4 F 2007-08-19 00:00:00.000 1900-01-01 00:00:00.000 1
5 R 2007-08-19 00:00:00.000 1900-01-01 00:00:00.000 1
6 R 2007-08-01 00:00:00.000 2007-08-05 00:00:00.000 0

（所影响的行数为 6 行）

------解决方案--------------------
insert into ta (id,MyType,Adate,MySign) select 1,'R','2007-8-25',0
insert into ta (id,MyType,Adate,MySign) select 2,'F','2007-8-2',0
insert into ta (id,MyType,Adate,MySign) select 3,'F','2007-8-26',0
insert into ta (id,MyType,Adate,MySign) select 4,'F','2007-8-19',0
insert into ta (id,MyType,Adate,MySign) select 5,'R','2007-8-19',0
insert into ta (id,MyType,Adate) select 6,'R','2007-8-17'

update ta set MySign=(case when datepart(dw,Adate)=1 then 1 else 0 end),