I will post those things...but just quick about the datamodel...we have to take our data from system21(DB2)..a 1980's linked lib's DB with no validation or relations....So not much I can...
The reason for the #Temp table inside the cursor was to make sure no duplicates got through, because there are row exactly the same in the input table,...