Fix upgrade bug - sql statement should have been in loop, next one had incorrect
parameter.