Fix some inconsistencies in SQL requests building