SQL Server/T-SQL Tutorial/String Functions/SOUNDEX
Содержание
Determining the Similarity of Strings
3>
4> SELECT SOUNDEX("Fleas"),
5> SOUNDEX("Fleece"),
6> SOUNDEX("Peace"),
7> SOUNDEX("Peas")
8> GO
----- ----- ----- -----
F100 F120 P200 P000
(1 rows affected)
1>
Sound difference
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
SOUNDEX checks how similarly sounding two tested strings can be.
3> SELECT SOUNDEX("Robin Dewson"), SOUNDEX("Robyn Jewshoon")
4> GO
----- -----
R215 R210
(1 rows affected)
SOUNDEX("Knight")
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>