How to add previous row end date as the next row start date?

  • Sean Lange (3/18/2014)


    dwain.c (3/18/2014)


    I believe that this article might be relevant to your question:

    Creating a Date Range from Multiple Rows Based on a Single Date[/url]

    As soon as I saw the title of this article in my email today I thought of this thread. Well done yet again Dwain!!!

    Thanks Sean! I've just seen the same question come up so often I decided it was time to get something like this out.


    My mantra: No loops! No CURSORs! No RBAR! Hoo-uh![/I]

    My thought question: Have you ever been told that your query runs too fast?

    My advice:
    INDEXing a poor-performing query is like putting sugar on cat food. Yeah, it probably tastes better but are you sure you want to eat it?
    The path of least resistance can be a slippery slope. Take care that fixing your fixes of fixes doesn't snowball and end up costing you more than fixing the root cause would have in the first place.

    Need to UNPIVOT? Why not CROSS APPLY VALUES instead?[/url]
    Since random numbers are too important to be left to chance, let's generate some![/url]
    Learn to understand recursive CTEs by example.[/url]
    [url url=http://www.sqlservercentral.com/articles/St

  • hi Can you please post the query

    thank you

  • SELECT a.ID

    ,DATEADD(day,ISNULL(SUM(b.AddDays),0),GETDATE())

    ,DATEADD(day,a.AddDays+ISNULL(SUM(b.AddDays),0),GETDATE())

    FROM #mytable a

    LEFT JOIN #mytable b ON b.ID < a.ID

    GROUP BY a.ID,a.AddDays

    Far away is close at hand in the images of elsewhere.
    Anon.

Viewing 3 posts - 16 through 17 (of 17 total)

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