This is very much a continuation of a previous thread (thread183-1365652), I am so sorry, but I am stuck. I now have a table with the below data and I am trying to get the resultset listed beneath. The previous thread did not have accountId in the mix, so it gets a bit more complicated. You have given me so many great replies and ideas, and I once again, I thank you in advance.
Table:
declare @TEST table(accountId int, startDate char(10), endDate char(10), amt float)
insert into @TEST
select 81987,'02/02/2007', '04/02/2007', -30.9055
union select 81987,'02/05/2007', '04/02/2007', -82.4146
union select 81987,'02/06/2007', '04/02/2007', -30.396
union select 90000,'02/02/2007', '04/02/2007', -40.00
union select 90000,'02/05/2007', '04/02/2007', -50.00
union select 90000,'02/06/2007', '04/02/2007', -60.00
ResultSet
accountId startDate endDate amt
----------------------------------------------------------
81987 02/02/2007 02/05/2007 -30.9055
81987 02/05/2007 02/06/2007 -113.3201
81987 02/06/2007 04/02/2007 -143.7161
90000 02/02/2007 02/05/2007 -40
90000 02/05/2007 02/06/2007 -90
90000 02/06/2007 04/02/2007 -150
Table:
declare @TEST table(accountId int, startDate char(10), endDate char(10), amt float)
insert into @TEST
select 81987,'02/02/2007', '04/02/2007', -30.9055
union select 81987,'02/05/2007', '04/02/2007', -82.4146
union select 81987,'02/06/2007', '04/02/2007', -30.396
union select 90000,'02/02/2007', '04/02/2007', -40.00
union select 90000,'02/05/2007', '04/02/2007', -50.00
union select 90000,'02/06/2007', '04/02/2007', -60.00
ResultSet
accountId startDate endDate amt
----------------------------------------------------------
81987 02/02/2007 02/05/2007 -30.9055
81987 02/05/2007 02/06/2007 -113.3201
81987 02/06/2007 04/02/2007 -143.7161
90000 02/02/2007 02/05/2007 -40
90000 02/05/2007 02/06/2007 -90
90000 02/06/2007 04/02/2007 -150