Fix issue with optional SQL