Quantcast
Channel: SQLServerCentral » SQL Server 2014 » Development - SQL Server 2014 » Latest topics
Viewing all articles
Browse latest Browse all 3145

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

$
0
0
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. [b] [u]ID[/u][/b] [b][u]effdate[/u][/b] [b][u]termdate[/u][/b] 556868 1999-01-01 1999-06-30 556868 1999-07-01 1999-10-31 556869 2002-10-01 2004-01-31 556872 1999-02-01 2000-08-31 556872 2000-11-01 2004-01-31 556872 2004-02-01 2004-02-29 output should be ...... [b] [u]ID[/u][/b] [b][u]effdate[/u][/b] [b][u]termdate[/u][/b] 556868 1999-01-01 1999-10-31 556869 2002-10-01 2004-01-31 556872 1999-02-01 2000-08-31 556872 2000-11-01 2004-02-29[quote][/quote]

Viewing all articles
Browse latest Browse all 3145

Trending Articles