2010-06-01 178 views
2

我在表中的数据如下。更新日期时间在SQL Server 2000中的日期部分

col1     col2     col3 
-------------------------------------------------------- 
6/5/2010 18:05:00 6/2/2010 10:05:00   Null 
6/8/2010 15:05:00 6/3/2010 10:45:00  6/5/2010 11:05:00 
6/3/2010 15:05:00 Null     6/7/2010 12:05:00 
6/1/2010 15:05:00 6/3/2010 10:45:00  6/1/2010 14:05:00 

我的要求是什么我想更新日期那里列与单个日期而不打扰时间。例如说我想更新6/1/2010的表格数据,其中的字段数据不为空。请让我知道更新表格数据的查询。

感谢&问候,

穆拉利

回答

6

我认为这应该为你工作。

create table #t 
(
col1 datetime 
) 

Insert Into #t 
values ('2010-06-01 10:00:00') 

Insert Into #t 
values ('2010-06-06 11:00:00') 

Insert Into #t 
values ('2010-05-24 12:40:00') 

Insert Into #t 
values ('2010-05-07 13:00:00') 

Insert Into #t 
values (Null) 

declare @newDate datetime 

set @newDate = '2010-07-01' 

update #t 
Set col1 = DateAdd(day, DateDiff(day, col1, @newDate), Col1) 
Where Col1 is not null 


select * From #t 

drop table #t 
0

您可能需要通过SELECT语句来做到这一点,你不需要给每个新数据添加到表时运行UPDATE语句