Weekend data in SQL server 2000

  • Hello There

    I need some help from the experts. I have a report requirement. My question is how to retrieve data from the table based on weekends i.e( sat and sun) in a specified month. I am using sql server 2000.

    Thanks

  • Try using this in your query.

    SELECT * FROM tablenae WHERE DATEPART(dw, datecolumn) IN (1, 7);

  • Thanks a lot. that worked.

    I have another requirement where I want to retrieve data from the table after working hours (i.e)

    Monday-Thursday : after 6pm and before 8am

    and on weekends full day i.e from Friday 6pm to Monday -8am that includes Sat and Sunday)

    Thanks once again.

  • You can answer that one yourself. Use the DATEPART function again. If you don't know the syntax, you'll find it in Books Online or on the web.

    John

  • There's a very similar thread here.


    [font="Arial"]Low-hanging fruit picker and defender of the moggies[/font]

    For better assistance in answering your questions, please read this[/url].


    Understanding and using APPLY, (I)[/url] and (II)[/url] Paul White[/url]

    Hidden RBAR: Triangular Joins[/url] / The "Numbers" or "Tally" Table: What it is and how it replaces a loop[/url] Jeff Moden[/url]

  • padhis (1/6/2012)


    Try using this in your query.

    SELECT * FROM tablenae WHERE DATEPART(dw, datecolumn) IN (1, 7);

    Better make real sure what the DATEFIRST setting is if you're going to use that method. 😉

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.

    Change is inevitable... Change for the better is not.


    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)

Viewing 6 posts - 1 through 5 (of 5 total)

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