finished 1st draft proc conversion, fix typos in sql