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
 General SQL Server Forums
 New to SQL Server Programming
 7 days prior to today

Author  Topic 

nevermore507
Starting Member

2 Posts

Posted - 2012-03-24 : 21:02:23
I'm trying to pull records that were entered 7 days prior to today. The table is orders and the column is opendate. I tried the below but as you know, it didn't work. Any help would be appreciated

select
orderno, opendate
from
orders
where
opendate <= datesub(d,7,getdate())

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2012-03-24 : 21:09:01
there's no datesub. it should be

...
where
opendate >= dateadd(dd,datediff(dd,0,getdate())-7,0)
and opendate < dateadd(dd,datediff(dd,0,getdate())+1,0)


------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

nevermore507
Starting Member

2 Posts

Posted - 2012-04-05 : 11:37:06
Thank you!
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2012-04-05 : 11:44:39
welcome

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -