我想在长句中使用SOUNDEX()
和DIFFERENCE()
函数,包含多个单词。到目前为止我发现的是这两个函数对单个单词起作用。例如:
"Stackoverflow is a very good website"
如果我使用DIFFERENCE("Stackoverflow is a very good website")
,它只会匹配句子第一个单词的差异,即“stackoverflow” - 而不是其他单词的差异。我实际上是在尝试在SQL中构建一个拼写建议查询,如果我们输入错误,google会向我们显示正确的拼写方式。
请帮忙。
这是我的代码:
DECLARE @Sound1 AS VARCHAR(4)
DECLARE @Sound2 AS VARCHAR(4)
DECLARE @Equals AS BIT
DECLARE @str1 AS VARCHAR(50)
DECLARE @str2 AS VARCHAR(50)
DECLARE @Difference AS INTEGER
SET @str1 = 'Stackoverflow is a very good website'
SET @str2 = 'Stackovxxflow'
SET @Sound1 = SOUNDEX(@str1)
SET @Sound2 = SOUNDEX(@str2)
IF(@Sound1 <> @Sound2)
BEGIN
SET @Difference = DIFFERENCE(@str1, @str2)
IF(@Difference <= 4)
BEGIN
SELECT TOP 1 [Address] FROM _Employee
ORDER BY DIFFERENCE([Address],@str2) DESC
END
END