Calc_Diff and CopyOfAll_Grouped are tables and don't contain SQL, to my knowledge.
As for the purpose of the rsAll.MoveNext occurrence, the code is supposed to determine if the difference between [Amount] and [Amount_Cur] is less than 0. If it is, then make the TotAmt the AvgDiff (the...