can you please post desired resultset?Using this as example:set nocount ondeclare @test table (Merchant char(5), MerchantID int, Purchase datetime, Paid datetime, daysBetween int)insert into @test select 'xxxxx', 1, '4/6/1999', '10/31/1999', 208 union select 'xxxxx', 1, '8/9/1999', '12/31/1999', 144 union select 'xxxxx', 1, '10/12/2000', '1/16/2001', 96 union select 'xxxxx', 1, '1/16/2001', '2/28/2001', 43 union select 'xxxxx', 1, '3/23/2001', '7/23/2001', 122 union select 'xxxxx', 1, '5/29/2002', '12/12/2002', 197 union select 'xxxxx', 1, '12/3/2002', '6/23/2003', 202 union select 'xxbgt', 2, '6/15/1999', '11/30/1999', 168 union select 'xxbgt', 2, '1/13/2000', '5/31/2000', 139 union select 'xxbgt', 2, '3/27/2000', '8/31/2000', 157 union select 'xxghy', 3, '4/18/2000', '10/31/2000', 196 union select 'xxghy', 3, '2/14/2001', '5/31/2001', 106 union select 'xxghy', 3, '6/20/2001', '1/3/2002', 197 union select 'xxghy', 3, '10/17/2001', '3/27/2002', 161 union select 'xbabd', 5, '3/22/2002', '10/7/2002', 199 union select 'xbabd', 5, '4/24/2003', '9/24/2003', 153select * from @test