MSSQL Similarity Rate
Hey,
Today I will tell you how can calculate the 2 strings similarities. I used this method for adding products to the product table. Why?
Because most of the users generally didn't check the product is added before, they feel more comfortable just creating a new registration. I don't want to let this, lets look at how we can do this
I used the replace method in MsSQL, as you know replace method gets 3 inputs, the first of 2 are input strings, last one for replacing. I inspired by the Turing machine(if you don't what is this, please check it)
Let's assume you give a string to the Turing machine and you want to calculate is it included with the same count of a and b. it will read the string and it will replace to one by one with the # symbol. if it read one ‘a’ it will replace with # and it will search b for replacing with #. After replacing the transactions, if there is just # in the string it means a and b equal.
I used the same technic to calculate the similarities
declare @first as nvarchar(255)=’this is the string’
declare @second as nvarchar(255)=’this is’select (1.0-CAST(len(replace(TRIM(@first),TRIM(@second),''))/CAST(len(@first)
AS FLOAT) AS FLOAT))*100 similarity,(CAST(len(replace(@second,@first,''))/CAST(len(@first) AS FLOAT) AS FLOAT))*100 differenceselect (replace(TRIM(@first),TRIM(@second),'')),(replace(TRIM(@second),TRIM(@first),''))
I hope it will be useful for you.