Exclude Saturday and Sunday from Query

  • I am looking to count daily data but want to exclude Sat and Sunday .

    So when I look for Yesterday's numbers .. it should show me the numbers for Friday on a Monday.

    Is there any other way rather than filtering out week 1 and 7 in the query

    DATEPART(dw,getdate()) NOT IN( '1' ,'7')

  • For problems such as that (and many more), it can be convenient to have a Calendar table in your database. A simple table with one row per date, showing the date (primary key) and a lot of attributes such as day of week, week number, month, fiscal year, etc etc etc.

    Such a table also makes it a lot easier to do tests for business days (excluding not only saturday and sunday but also national holidays and business-specific holidays)


    Hugo Kornelis, SQL Server/Data Platform MVP (2006-2016)
    Visit my SQL Server blog: https://sqlserverfast.com/blog/
    SQL Server Execution Plan Reference: https://sqlserverfast.com/epr/

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

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