select sql statement builder refactor