how to get data for next 3 months

  • Hi,

    i know the syntax dateadd(month,3,datefield) which will add 3 months and you can only see one month..

    but i want a syntax to see all next 3 months of data .

    Ex:if datefield ='2010-01-01' i want the data for next 3 months i.e

    2010-02-01,

    2010-03-01,

    2010-04-01.

  • itskumar2004 (2/1/2010)


    Hi,

    i know the syntax dateadd(month,3,datefield) which will add 3 months and you can only see one month..

    but i want a syntax to see all next 3 months of data .

    Ex:if datefield ='2010-01-01' i want the data for next 3 months i.e

    2010-02-01,

    2010-03-01,

    2010-04-01.

    assuming you have a table with that datetime filed, you would want to use a BETWEEN statement to get everything between teh range you are looking for:

    ie

    SELECT * FROM MYTABLE

    --betweent eh date and the date plus three months

    WHERE MYDATEFIELD BETWEEN @DateParameter and dateadd(month,3,@DateParameter )

    Lowell


    --help us help you! If you post a question, make sure you include a CREATE TABLE... statement and INSERT INTO... statement into that table to give the volunteers here representative data. with your description of the problem, we can provide a tested, verifiable solution to your question! asking the question the right way gets you a tested answer the fastest way possible!

  • hi,

    it should fetch the next 3 months for my given date which is going to be a parameter in my stored procedure ,for whatever date we give it should fetch data for next 3 months...i dont know the range

    i.e if datefield is the column i have in the table and if datefield=2010-01-01 which is going to be a parameter it should fetch data for next 3 months..

  • What requirement cannot be achieved with Lowells solution?

    The BETWEEN clause will "fetch data for next 3 months" as per your requirement.

    If you need more assistance you might want to provide more detailed information.

    Repeating what you already posted doesn't help...



    Lutz
    A pessimist is an optimist with experience.

    How to get fast answers to your question[/url]
    How to post performance related questions[/url]
    Links for Tally Table [/url] , Cross Tabs [/url] and Dynamic Cross Tabs [/url], Delimited Split Function[/url]

  • I am sorry for my confusion.i got the results using the syntax thanks for that ...

    My results are including the datefield column below(2010-01-01) ,Can you also tell me how should i exclude it and only get next 3 months of data

    Ex:if datefield ='2010-01-01' i want the data for next 3 months i.e

    2010-02-01,

    2010-03-01,

    2010-04-01.

    Please correct me if i am wrong..

  • Using Lowells sample:

    SELECT * FROM MYTABLE

    --betweent eh date and the date plus three months

    --WHERE MYDATEFIELD BETWEEN @DateParameter and dateadd(month,3,@DateParameter )

    WHERE MYDATEFIELD > DateParameter

    AND MYDATEFIELD <=dateadd(month,3,@DateParameter )



    Lutz
    A pessimist is an optimist with experience.

    How to get fast answers to your question[/url]
    How to post performance related questions[/url]
    Links for Tally Table [/url] , Cross Tabs [/url] and Dynamic Cross Tabs [/url], Delimited Split Function[/url]

  • Thanks a lot ..

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

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