T-SQL is poor in fuzzy searches. Your best bet is third-party libraries, but if you don't want to conflict with this, it is best to use the DIFFERENCE function built into SQL Server. For instance:
SELECT * FROM tblUsers U WHERE DIFFERENCE(U.Name, @nameEntered) >= 3
A higher return value for DIFFERENCE indicates a higher precision. The disadvantage of this is that the algorithm supports words that sound the same, which may not be your desired characteristic.
The following example shows how to get the best match from a table:
DECLARE @users TABLE (Name VARCHAR(255)) INSERT INTO @users VALUES ('Dylan'), ('Bob'), ('Tester'), ('Dude') SELECT *, MAX(DIFFERENCE(Name, 'Dillon')) AS SCORE FROM @users GROUP BY Name ORDER BY SCORE DESC
It returns:
Name | Score Dylan 4 Dude 3 Bob 2 Tester 0
source share