fixing endpoint sql