SQLTeam.com | Weblogs | Forums

SQL Max Date query to last 30 Days


#1

I have the following statement that currently gets me a specific date, in this case 30 days back. I'm having a brain fart on making the adjustment to pull the combined last 30 days of data, through today, on this one.

Normally this statement excludes the "- 30" and just pulls the data for the current date.

MAX( DT.sql_date )- 30                            as TimeframeStart
                    , CAST( CAST( GETDATE() as DATE ) as DATETIME )- 30 as TimeframeEnd

#2

dateadd(day, -30, max(dt.sql_date))


#3

that worked great, thanks!