fix Grid search query sql