...TrxDate <= @endmonth
group by account) c1
on c.account = c1.account
set @month = DateAdd(Month, DateDiff(Month, 0, @month)+1, 0)
set @endmonth = DateAdd(Month, DateDiff(Month, 0, @endmonth)+2, 0)-1
select @month, @endmonth
set @int = @int + 1
end
select *
from #customertotals