SARGABLE way of getting orders from exactly 10 days ago

  • Could someone help me out with this logic.

    I have an order table with an Order_Date column. I need all the orders from 10 days ago(for example All the orders that were placed on the 9th if the query runs today)

    What's the best Sargable way to do this?

  • select (columns needed)

    from Table

    where DateColumn >= cast(dateadd(day, -10, getdate()) as Date)

    and DateColumn < cast(dateadd(day, -9, getdate()) as Date);

    - Gus "GSquared", RSVP, OODA, MAP, NMVP, FAQ, SAT, SQL, DNA, RNA, UOI, IOU, AM, PM, AD, BC, BCE, USA, UN, CF, ROFL, LOL, ETC
    Property of The Thread

    "Nobody knows the age of the human race, but everyone agrees it's old enough to know better." - Anon

  • Thanks again GS!!

Viewing 3 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply