日期:2014-05-19  浏览次数:20652 次

100分求教一个sql语句
表中有一字段   记录时间(datetime),  

现在想将该字段记录里的   日期   改为某一指定日期,而   时间   不变   .

比如:原来为 '2006-01-01   01:10:00.000 '

          指定日期为:2008-12-25  
           
          改变后为 '2008-12-25   01:10:00.000 '

试了能行的就给分.
在线等...

------解决方案--------------------
??
print stuff(convert(varchar(30), '2006-01-01 01:10:00.000 ',120),1,10, '2008-12-25 ')
------解决方案--------------------
--更新年份为任意一年
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())