Here is one function that I found recently to get two string and compare them to determine the possibility of matching rate.
CODE
create function CompareText (@String1 varchar (50), @String2 varchar (50))
returns integer
--Function CompareText
--blindman 4/2005, Adapted from MS Access algorithm developed 1997
--Returns value between 0 and 100 indicating the similarity between two character strings.
--usage: select * from [Table] where dbo.CompareText([ColumnValue], 'SearchString') > 80
begin
declare @Possibles integer
declare @Hits integer
declare @Counter integer
set @Possibles = len(@String1) + len(@String2) - 2
set @Hits = 0
set @Counter = len(@String1)-1
while @Counter > 0
begin
if charindex(substring(@String1, @Counter, 2), @String2) > 0 set @Hits = @Hits + 1
set @Counter = @Counter - 1
end
set @Counter = len(@String2)-1
while @Counter > 0
begin
if charindex(substring(@String2, @Counter, 2), @String1) > 0 set @Hits = @Hits + 1
set @Counter = @Counter - 1
end
return (100*@Hits)/@Possibles
end
SOSFrom the code above, I modify to get list of matching character from my DB table and concat into a full string instead like below:
CODE
// Get percentage of matching rate
SELECT @TableValueComparisonindex = (100*@Hits)/@Possibles
// If matching rate is more than 20%, concat the current DB record into the full string
IF @TableValueComparisonindex >= 20
BEGIN
SET @CompleteMatchingStrings = @CompleteMatchingStrings + @DBTableValue + @StringSeparator
END
After returning the full string to my application, I will format and show list of matching character by user input. Perhaps you can use this for reference