data for only week days

db , sql server India
  • 11 years ago

    Hi Friends,

    I need to write a query  in such away to extract the data from SQL server 2005 database for the LAST_MONTH Data and only WEEK days excluding the weekend days







    There is all 31 days in the ORDERDATE but I need to exclude the WEEKENDS ...

    for the last Month.Please help ...!!!!!


    Thanks in Advance



  • 10 years ago

    Try something like this:

    select OrderDate
    from Orders
    inner join
            datepart(yyyy, max(OrderDate)) as 'lastYear',
            datepart(mm, max(OrderDate)) as 'lastMonth'
        from Orders
    ) xxx
    on (datepart(yyyy, Orders.OrderDate) = xxx.lastYear)
    and (datepart(mm, Orders.OrderDate) = xxx.lastMonth)
    where (datepart(dw, OrderDate) between 2 and 6)


    Not perhaps as efficient as it could be but its a good enough starting point for you.


Post a reply

Enter your message below

Sign in or Join us (it's free).


Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“C++ : Where friends have access to your private members.” - Gavin Russell Baker