仅更新sql server 2000中datetime的日期部分

use*_*146 2 sql-server 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 
Run Code Online (Sandbox Code Playgroud)

我的要求是什么我想用单日期更新那些列的日期而不打扰时间.比方说,我想用6/1/2010更新表数据,其中字段数据不为空.请让我知道更新表数据的查询.

感谢和问候,

穆拉利

cod*_*ger 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
Run Code Online (Sandbox Code Playgroud)