Community discussion forum

data for only week days

  • 8 months 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

     

  • Advertisement

    Simply the fastest line-level profiler for .NET ever

    “The low overhead means it has minimal impact on the execution of my program”
    Mark Everest, Development Team Leader, Renault F1 Team Ltd.

    Try out the new ANTS Profiler 4 for yourself. Download your 14-day trial now

  • 6 months 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).