fixes to sql statements