SQL Query to make a single records from multiple records based on different fields of different records

  • I need help in writing the query for the following, I need to collapse the continuity. If the termdate for an ID is one day less than the effdate of the next id (for the same ID) i need to collapse the records. See below example .....how should i write the query which will give me the desired output. i.e., get min(effdate) and max(termdate) if termdate is one day less than the effdate of next record. Your help is appreciated. Thanks.

    ID effdate termdate

    5568681999-01-01 1999-06-30

    5568681999-07-01 1999-10-31

    5568692002-10-01 2004-01-31

    5568721999-02-01 2000-08-31

    5568722000-11-01 2004-01-31

    5568722004-02-01 2004-02-29

    output should be ......

    ID effdate termdate

    5568681999-01-01 1999-10-31

    5568692002-10-01 2004-01-31

    5568721999-02-01 2000-08-31

    5568722000-11-01 2004-02-29

  • Duplicate post. See http://www.sqlservercentral.com/Forums/Topic1552884-391-1.aspx

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

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