How to detect the last iteration in a loop

I would also use join, but if you insist on a loop, you can also check for the first element, and reorganize the logic a bit:

using InterTools
sql = "INSERT INTO table VALUES "
for (isfirst, oneRecord) in IterTools.flagfirst(records)
    if !isfirst
        sql *= ", "
    end
    sql *= "($val1, $val2, $oneRecord)"
end
sql *= ";"