Using SQL Server 2008R2, I have here is a simple query:
SELECT *
FROM ItemData
WHERE FREETEXT(Title, '"' + @OriginalSearchTerm + '"')
AND ( WebsiteID=@WebsiteID AND GeoCity = @GeoCity AND GeoState = @GeoState )
ORDER BY ItemListID DESC
This is all fine when there is a valid value for @GeoCity and @GeoState. However there will be scenarios where @GeoCity = -1 and/or @GeoState = -1.
I would rather not write entire separate queries for these cases, although this would work just fine.
How can I optimize the current query to do just this?
Thanks.
— This might be more efficient as OR statement executes block for each OR statement.