Sql 如何找到两个字符串变量之间的相似性?
我需要你帮个忙。我有两根绳子Sql 如何找到两个字符串变量之间的相似性?,sql,sql-server,sql-server-2008,Sql,Sql Server,Sql Server 2008,我需要你帮个忙。我有两根绳子 First String ==> "This is for test." Second String ==> "This is a for test." 我希望输出基于以下条件 If first string half count of words or all words exist in second string then it will return true. If first string more then half count
First String ==> "This is for test."
Second String ==> "This is a for test."
我希望输出基于以下条件
If first string half count of words or all words exist in second string then it will return true.
If first string more then half count words is not exist in second string then it will return false.
OP
如果输入
First String ==> "This is for test."
Second String ==> "This is a for test."
First String ==> "This is for test."
Second String ==> "This is a "
First String ==> "This is for test."
Second String ==> "This "
然后输出
TRUE
TRUE
FALSE
如果输入
First String ==> "This is for test."
Second String ==> "This is a for test."
First String ==> "This is for test."
Second String ==> "This is a "
First String ==> "This is for test."
Second String ==> "This "
然后输出
TRUE
TRUE
FALSE
如果输入
First String ==> "This is for test."
Second String ==> "This is a for test."
First String ==> "This is for test."
Second String ==> "This is a "
First String ==> "This is for test."
Second String ==> "This "
然后输出
TRUE
TRUE
FALSE
Sql Server 2008中有一个SplitBy函数可用于此任务:
create FUNCTION [dbo].[SplitBy](@String varchar(8000), @Delimiter char(1))
returns @temptable
TABLE (nameIndex int identity(1,1),items varchar(8000))
as
begin
declare @idx int
declare
@slice varchar(8000)
select @idx = 1
if len(@String)<1 or @String
is null return
while @idx!= 0
begin
set @idx =
charindex(@Delimiter,@String)
if @idx!=0
set @slice = left(@String,@idx
- 1)
else
set @slice = @String
if(len(@slice)>0)
insert
into @temptable(Items) values(@slice)
set @String =
right(@String,len(@String) - @idx)
if len(@String) = 0 break
end
return
end
我希望有帮助
SplitBy函数参考:类似于您的上一个问题。。。考虑到你的要求,不可能说出来。我会将每个字符串解析为标记,并计算某种匹配百分比。将根据阈值确定正确/错误。我会研究Python的NLTK之类的东西。类似的东西也可能有帮助: