在sqlserver数据库中,如何得到当前日期任意天前的日期? 例如今天是2007-9-13,我要得到一天前,两天前 ,一个星期前,一个月前。。的日期,这个是在做查询是要用到的,麻烦高手指点一下!小弟不胜感激! 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 declare @ndays intset @ndays=3select dateadd(day,-@ndays,getdate())-----------------------2007-09-10 14:23:18.830(1 row(s) affected) declare @ndays int, @nweeks int, @nmonths intselect @ndays=3,@nweeks=3,@nmonths=3select dateadd(day,-@ndays,getdate()) as SomedaysAgo ,dateadd(wk,-@nweeks,getdate()) as SomeweekssAgo ,dateadd(m,-@nmonths,getdate()) as SomemothsAgo/******SomedaysAgo SomeweekssAgo SomemothsAgo----------------------- ----------------------- -----------------------2007-09-10 14:26:30.690 2007-08-23 14:26:30.690 2007-06-13 14:26:30.690**********/ DATEADD (datepart , number, date ) 求一sql语句,这样的功能能否实现(我又来了)? 一个多表查询的问题 很久没写SQL,同志们来帮个忙写个SQL语句.... 在用DISTINCT的时候,如何返回该组中有多少个。 求助语句该如何写? 请教一个查询语句 请教怎么按“行”UPDATE和COUNT 表中有个字段是”年月”,我想对年月在指定日期间的数据进行update处理,应该怎么写这个条件?? 要死了,这样的数据库怎样恢复 脚本长度 SQL查询问题~~急~~group by 出了问题~~ 邹建写的一个年结存储过程
set @ndays=3
select dateadd(day,-@ndays,getdate())-----------------------
2007-09-10 14:23:18.830(1 row(s) affected)
@nweeks int,
@nmonths int
select @ndays=3,@nweeks=3,@nmonths=3
select dateadd(day,-@ndays,getdate()) as SomedaysAgo
,dateadd(wk,-@nweeks,getdate()) as SomeweekssAgo
,dateadd(m,-@nmonths,getdate()) as SomemothsAgo
/******
SomedaysAgo SomeweekssAgo SomemothsAgo
----------------------- ----------------------- -----------------------
2007-09-10 14:26:30.690 2007-08-23 14:26:30.690 2007-06-13 14:26:30.690
**********/