Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

LATEST DATE

Status
Not open for further replies.

Nsan

MIS
Apr 30, 2003
13
0
0
Using SQL Server 2005 I need to return data based on the latest(highest) date value in a column and 7 days back. Any help would be great.
 
What have you tried so far?

-George

"The great things about standards is that there are so many to choose from." - Fortune Cookie Wisdom
 
try this

Select * from table where date_column between getdate() and getdate()-7

 
That will only work if you want to consider the time portion of the datetime column. To get a true 7 day difference, you have to ignore the time.
 
and also GETDATE() is not necessary MAX(DateField) in the table :)

Borislav Borissov
VFP9 SP2, SQL Server 2000/2005.
 
Hi,

I would use the following...

Code:
select * 
from [Table] 
where [DateField] between dateadd(d,-7,floor(cast(getdate() as float))) and getdate()

Ryan
 
... where date_column between getdate() and getdate()-7
that will never work, ever


it's like saying

... where integer_column between 42 and 35

never, ever, ever

:)


r937.com | rudy.ca
 
Great information..

Thanks..
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top