Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 Transact-SQL (2000)
 Pulling 2 weeks data

Author  Topic 

ninel
Posting Yak Master

141 Posts

Posted - 2008-03-13 : 11:17:25
I have to create a daily file that pulls 2 weeks worth of data.
So if I create a file today(3/13), I need data from 2/28 - 3/13.
Tomorrow's file (3/14) should contain data from 2/29 - 3/14 and so on.

Does anyone know how to do this?
Thanks,
Ninel

jhocutt
Constraint Violating Yak Guru

385 Posts

Posted - 2008-03-13 : 11:21:05
Look in BOL for DateAdd

"God does not play dice" -- Albert Einstein
"Not only does God play dice, but he sometimes throws them where they cannot be seen."
-- Stephen Hawking
Go to Top of Page

jimf
Master Smack Fu Yak Hacker

2875 Posts

Posted - 2008-03-13 : 11:36:06
SELECT * FROM yourTable
WHERE somedateCol >= DATEADD(week,-2,@today)
and somedateCol >= DATEADD(week,@today)

Jim
Go to Top of Page

Michael Valentine Jones
Yak DBA Kernel (pronounced Colonel)

7020 Posts

Posted - 2008-03-13 : 11:57:11
[code]
select
*
from
MyTable
where
-- MyDateCol GE 14 days before today at 00:00:00
MyDateCol >= dateadd(dd,datediff(dd,0,getdate())-14,0)
and
-- MyDateCol before tomorrow at 00:00:00
MyDateCol < dateadd(dd,datediff(dd,0,getdate())+1,0)


[/code]

CODO ERGO SUM
Go to Top of Page
   

- Advertisement -