So this is a quick note to myself as I was playing with the relevance heuristics of a query. This example adds a column of relevance and sorts the rows accordingly.
How?
This has to be a real quick one for a dropdown search field which has to find relevant terms to autofill/autocomplete a search form:
-- where @ThisSearch is a posted (and sanitized) variable
SET @ThisSearch:="Brains";
SELECT
columnID,
columnFullName,
CASE
WHEN columnFirstName LIKE @ThisSearch THEN 20
WHEN columnFullName LIKE @ThisSearch THEN 10
WHEN columnLastName LIKE @ThisSearch THEN 10
WHEN columnFullName LIKE @ThisSearch THEN 1
END as relevance
FROM
myTable
WHERE
s.columnPublished
Discussion
Comments
Questions, corrections and useful additions are reviewed before appearing here.
No comments yet. Start the discussion.