updated sql functions to use macro