I have the following SQL Server query:
SELECT area
FROM places
WHERE REPLACE(area,'-',' ') LIKE REPLACE('%moreto%','-',' ')
That returns the following results:
Moreton Pinkney, Northamptonshire
South Moreton, Oxfordshire
North Moreton, Oxfordshire
Moreton, Merseyside
Moreton-in-Marsh, Gloucestershire
Moreton Jeffries, Herefordshire
Moreton on Lugg, Herefordshire
Maids' Moreton, Buckinghamshire
Moreton Corbet, Shropshire
Moretonhampstead, Devon
Is there any way that I can order the results based on the position of the found LIKE phrase? For example, if someone is typing ‘moreto’, the chances are that they’re typing the word from the beginning and not the middle.
Also, before anyone mentions – I do realise I could achieve these results by removing the first wildcard (%) but just wondered if there was another way to do it without being required too.
Many thanks.
This should do the trick
http://msdn.microsoft.com/en-us/library/ms188395.aspx