syntax fixes / optimization on sql call