changed build_sql to use jinja templating