declare @date datetime
set @date='2005-12-11 10:10:10'
select cast('2005-01-01 '+convert(char(8),@date,108) as datetime)/*
------------------------------------------------------ 
2005-01-01 10:10:10.000(所影响的行数为 1 行)
*/

解决方案 »

  1.   

    declare @t table(date datetime)
    insert into @t select '2005-12-11 10:10:10'
    update @t set date=cast('2005-01-01 '+convert(char(8),date,108) as datetime)
    select * from @t
    /*
    date
    -----------------------
    2005-01-01 10:10:10.000
    */
      

  2.   

    --更新年份为任意一年
    declare @year int
    set @year=2004
    update 表 set 日期=dateadd(year,@year-year(getdate()),getdate())--更新月份为任意一月
    declare @month int
    set @month=10
    update 表 set 日期=dateadd(month,@month-month(getdate()),getdate())
    --更新日为任意一日
    declare @day int
    set @day=22
    update 表 set 日期=dateadd(day,@day-day(getdate()),getdate())
      

  3.   

    create table A
    (
       id int,
       T_date datetime
    )
    insert A select 1,'2005-01-01 10:10:10'
    insert A select 2,'2005-01-01 10:11:10'
    insert A select 3,'2005-01-01 10:12:10'
    insert A select 4,'2005-01-01 10:13:10'create table B
    (
       id int,
       T_date datetime
    )
    insert B select 1,'2005-11-01 13:10:10'
    insert B select 2,'2005-12-01 12:11:10'
    insert B select 3,'2005-11-23 14:12:10'
    insert B select 4,'2005-10-21 11:13:10'update A set T_date=dateadd(dd,T.num,A.T_date)
    from A,
    (select A.id,datediff(dd,A.T_date,B.T_date) as num from A,B where A.id=B.id) T
    where A.id=T.idselect * from A
      

  4.   

    --最简单的方法:update 表 set 日期字段 = stuff(日期字段,1,10,'2005-01-01')
    --例如
    declare @tb table (daytime datetime)
    insert @tb 
    select '2005-12-11 10:10:10 ' union
    select '2005-10-18 10:10:10 '
    select * from  @tb
    update @tb set daytime = stuff(daytime,1,10,'2005-01-01')
    select * from @tb
      

  5.   

    后面时间保持原来的???insert table tabletabme select date='2006-01-01' from tablename where date='2005-12-10'