Your friend's code will work but has restrictions in that there must be 10 and only 10 lot quantity columns. I have not yet opened your db but gather the columns are named r01Qty, r02Qty, etc. Where does the RLastQty column magically come from?
OK, one of my routines will work inside the SQL as I indicated. What I will do is add it to your db suitably altered for your names and then send you back your db. Copy and paste will be the crude transfer method for you to transfer it across to your development db.
My solution works with any number of lot quantity columns as long as they are consistently named. However my caveat still applies: don't use it for tables with thousands of records.