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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

seeing the last 30 days from max(date) 1

Status
Not open for further replies.

ciarra41

Technical User
Sep 11, 2006
116
US
I’m trying to pull only the values from a date max value going back 30 days. So if I select the max date field it will pull that max date going back only 30 days.
Here’s what I have in mind but it’s pulling everything.

Having Max(date_post)> dateadd(d,datediff(d,0,date_post),-30)
Or a between would do ?
 
If I follow what you are trying to do something like the below should work...

Code:
Declare @Max_Date DateTime

Select @Max_Date = Max(date_post)
From Table

Select Date_Post
From Table
Where Date_Post Between dateadd(d,-30, @Max_Date) and @Max_Date
 
Try something like that:

Code:
Having DateDiff(d, date_post, Max(date_post)) <= 30

or

Code:
select * from Table1 
where DateDiff(d, date_post, (select Max(date_Post) from Table1)) <= 30

I hope this helps.


Imobiliárias em Suzano
 
Several ways to do that one....

select *
from list
where date > (select max(date)
from list)-30

Simi
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top