title: SQL Query sort by closest match
body: <p>We have a Locations search page that is giving us a challenge I've never run across before.</p>
  
  <p>In our database, we have a list of cities, states, etc. with the corresponding geocodes.  All was working fun until now...</p>
  
  <p>We have two locations in a city named "Black River Falls, WI" and we've recently opened one in "River Falls, WI".</p>
  
  <p>So our table has records as follows:</p>
  
  <pre><code>Location    City                State
  -------------------------------------
  1           Black River Falls   WI
  2           Black River Falls   WI
  3           River Falls         WI
  </code></pre>
  
  <p>Obviously our query uses a "LIKE" clause to match city, but when a customer searches the text "River Falls", in the search results, the first results shown are always "Black River Falls".  </p>
  
  <p>In our application, we always use the first match, and use it as the default.  (We could change it, but it would be a lot of un-budgeted work)</p>
  
  <p>I know I could simple change the sort order to have "River Falls" come up first, but that's a sloppy solution that works only in this one case.</p>
  
  <p>What I'm wondering is if there is a way, through T-SQL (SQL Server 2008r2) to sort by "best match" where "River Falls" would "win" if we search for "River Falls, WI" and "Black River Falls" would work if we search for "Black River Falls" WI.</p>