Hi @ahmed salah ,
There is a built-in SQL Server function: DIFFERENCE
DIFFERENCE compares two different SOUNDEX values, and returns an integer value. This value measures the degree that the SOUNDEX values match, on a scale of 0 to 4. A value of 0 indicates weak or no similarity between the SOUNDEX values; 4 indicates strongly similar.
Check it out a solution below.
I used 25 as a coefficient. You can try any other suitable number or even a formula to correlate for your needs.
SQL
DECLARE @tbl table (ID INT IDENTITY PRIMARY KEY, PartText varchar(50), MaskText varchar(50));
INSERT INTO @tbl (PartText,MaskText) VALUES
('TR00123907FG','KB00123907FG'),
('TR00123907FG','TR00123907FG'),
('klmhedf43122','50ghlpnkyzhy');
SELECT *
, Diff = DIFFERENCE(PartText, MaskText) * 25
FROM @tbl;
Output
+----+--------------+--------------+------+
| ID | PartText | MaskText | Diff |
+----+--------------+--------------+------+
| 1 | TR00123907FG | KB00123907FG | 50 |
| 2 | TR00123907FG | TR00123907FG | 100 |
| 3 | klmhedf43122 | 50ghlpnkyzhy | 0 |
+----+--------------+--------------+------+