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

    ORDERDATE

    03-01-2008

    .

    .

    03-31-2008

     

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

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

     

    Thanks in Advance

    Claoker

     

  • 10 years ago

    Try something like this:
     

    select OrderDate
    from Orders
    inner join
    (
        select
            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.

    Joe 

Post a reply

Enter your message below

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

Contribute

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