DF#QCADOOMES-1764 Added some fixes to sql.