cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
dpattengale
Frequent Visitor

Last 7 days query, error near '<'

 I have a query I am running it selects data from 2 tables. I am trying to get get both tables to uese the same date range. The query below was modified to try to get both tables to return the last 7 days worth of data. The blue text is what I added.

WHERE (d.TimeDown >= DATEADD(day, - 7, GETDATE(), (Date >= DATEADD(day, -7, GETDATE()))"]),  I get a syntax error near ">" which started when I added the second date statement. Can this be resolved, or am I writing this incorrectly? So far, my original table will pull the last 7 days as requested, but the second table delivers everything since 2005.

2 REPLIES 2
dpattengale
Frequent Visitor

No, I am looking for the past 7 days. Today, I would be looking for June 7th thru June13th from both tables One uses the the 'TimeDown' field as the date, the other currently uses 'Date' Note: I could use TimeOpen in table 2, which would give me two date/time fields (if that is easier).

amitchandak
Super User IV
Super User IV

@dpattengale , are you writing a SQL in advance option

 

try like

WHERE (d.TimeDown >= DATEADD(day, - 7, GETDATE()) and (d.TimeDown <= DATEADD(day, 0, GETDATE())))



Did I answer your question? Mark my post as a solution! Appreciate your Kudos!!
Dashboard of My Blogs !! YouTube Channel !! Connect on Linkedin

Proud to be a Super User!

Helpful resources

Announcements
PBI_User Group Leader_768x460.jpg

Manage your user group events

Check out the News & Announcements to learn more.

Get Ready for Power BI Dev Camp

Microsoft named a Leader in The Forrester Wave

Microsoft received the highest score of any vendor in both the strategy and current offering categories.

Get Ready for Power BI Dev Camp

Power BI Dev Camp - September 30th, 2021

Mark your calendars and join us for our next Power BI Dev Camp!

PowerPlatform 768x460.png

Microsoft Learn

Check out our new Discover Your Career Path blog post series and get all the details.