SQL Server/T-SQL Tutorial/String Functions/SOUNDEX

Материал из SQL эксперт
Перейти к: навигация, поиск

Determining the Similarity of Strings

   <source lang="sql">

3> 4> SELECT SOUNDEX("Fleas"), 5> SOUNDEX("Fleece"), 6> SOUNDEX("Peace"), 7> SOUNDEX("Peas") 8> GO


----- ----- -----

F100 F120 P200 P000 (1 rows affected) 1></source>


Sound difference

   <source lang="sql">

4> DECLARE @Word1 VarChar(100) 5> DECLARE @Word2 VarChar(100) 6> DECLARE @Value1 Int 7> DECLARE @Value2 Int 8> DECLARE @SoundexDiff Int 9> SET @Word1 = "Redmond" 10> SET @Word2 = "Renton" 11> SELECT @Value1 = CONVERT(Int, SUBSTRING(SOUNDEX(@Word1), 2, 3)) 12> SELECT @Value2 = CONVERT(Int, SUBSTRING(SOUNDEX(@Word2), 2, 3)) 13> SET @SoundexDiff = ABS(@Value1 - @Value2) 14> PRINT @SoundexDiff 15> GO 180</source>


SOUNDEX checks how similarly sounding two tested strings can be.

   <source lang="sql">

3> SELECT SOUNDEX("Robin Dewson"), SOUNDEX("Robyn Jewshoon") 4> GO


-----

R215 R210 (1 rows affected)</source>


SOUNDEX("Knight")

   <source lang="sql">

5> SELECT 6> "SX_KNIGHT"=SOUNDEX("Knight"), 7> "SX_NITE"=SOUNDEX("Nite"), 8> "DIFFERENCE"=DIFFERENCE("Nite", "Knight") 9> GO SX_KNIGHT SX_NITE DIFFERENCE


------- -----------

K523 N300 1 (1 rows affected) 1></source>