I have a table with "start date" column, and need to come up with "end date" based on other records for the same ID.As an example, for the following data:declare @t table (ID int,StartDate datetime,Name varchar(10))insert @tselect 1, '01/01/1980', 'N1' union allselect 1, '03/13/1985', 'N2' union allselect 1, '01/02/1989', 'N3' union allselect 1, '01/02/2008', 'N4' union allselect 1, '05/24/2009', 'N5' union allselect 2, '01/01/1981', 'B1'
I would expect this output:/*ID StartDate EndDate Name--------------------------------1 01/01/1980 03/12/1985 N11 03/13/1985 01/01/1989 N21 01/02/1989 01/01/2008 N31 01/02/2008 05/23/2009 N41 05/24/2009 12/31/9999 N52 01/02/2006 12/31/9999 B1*/
How can it be done?