Need help - Bteq logic required

Tools
N/A

Need help - Bteq logic required

Hi,

I need some help in putting a query together to achive desired output.

I have few records in a table where I have Acct_ID, Alert_ID, Alert_Name, Start_Date and End_Date. It represents historical information about a Alert Type for a Acct_ID.

The Alert will ahve start and end dates. Here is the data for a acct_ID.








This is how the data is coming
Acct_ID Alert_ID Alert_Name Start_Dt End_Dt
1234 4 Alert One 1/1/2015 1/31/2015
1234 4 Alert One 2/1/2015 2/28/2015
1234 4 Alert One 3/1/2015 3/31/2015
1234 4 Alert One 5/1/2015 5/31/2015
1234 4 Alert One 7/1/2015 7/31/2015
1234 4 Alert One 8/1/2015 8/30/2015
1234 4 Alert One 9/1/2015 12/31/9999

If you look at the first 3 records, there are no gaps. they start from 1/1/2015 and end on 3/31/2015.

4th record starts in May 1st and ends on May 31st.

again 5th and 6th records do not have gaps. they start on 7/1/2015 and end 8/30/2015.

the 7th one is the latest one with open end date.

I would like to write a query to combile first 3 records into one record and have the start_date for that record as 1/1/2015 and end_date as 3/31/2015. Basically I would like to combine records that doesn't have any gaps in dates.

below is how I would like to have my final data would be.








Acct_ID Alert_ID Alert_Name Start_Dt End_Dt
1234 4 Alert One 1/1/2015 3/31/2015
1234 4 Alert One 5/1/2015 5/31/2015
1234 4 Alert One 7/1/2015 8/30/2015
1234 4 Alert One 9/1/2015 12/31/9999

Can someone help me how to achive this in a BTEQ script? I would like to know if there are any teradata functions that I can use to achive the desired resultset. Your help is appreciated.