How to write a Query to get related result

  • I need help to write a query like below oupt put.

    create table #table (id int, cid int , startdate datetime)

    insert #table

    select 1, 100, '02/23/2014'

    union select 1, 100, '06/25/2013'

    union select 1, 100, '06/04/2013'

    union select 1, 100, '06/17/2013'

    union select 2, 200, '08/9/2013'

    union select 2, 200, '08/3/2013'

    First date 02/23/2014...So heere I need only the 2013 Current End dates Based On Start Date...

    I need oupt put like below table based on above table.

    id cid start_date end_date

    1 100 02/23/2014 --

    1 100 06/25/2013 12/31/2013

    1 100 06/04/2013 06/24/2013

    1 100 06/17/2013 06/03/2013

    2 200 08/9/2013 12/31/2013

    2 200 08/03/2013 08/08/2013

    Thanks,

  • duplicate post, please post replies at this post instead http://www.sqlservercentral.com/Forums/Topic1538410-392-1.aspx

    Jason...AKA CirqueDeSQLeil
    _______________________________________________
    I have given a name to my pain...MCM SQL Server, MVP
    SQL RNNR
    Posting Performance Based Questions - Gail Shaw[/url]
    Learn Extended Events

Viewing 2 posts - 1 through 1 (of 1 total)

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