您的位置:首页 > 其它

函数-判断两个关键字是否存在包含关系

2011-07-26 22:08 549 查看
create function [dbo].[Func_ContainsKeyWord]
--判断字符串A是否包含字符串B
--两个字符串的格式为:xxx,xxx,xxx,xxx
--判断依据:如果字符串A的包含字符串B的某个子项(被,分割的字符串)则返回1,否则返回0
(
@sourceKeyWords nvarchar(200),--字符串A
@targetKeyWords nvarchar(200) --字符串B
)
returns bit--返回值类型
as
begin
if Charindex(@targetKeyWords,@sourceKeyWords,1)>0
return 1;
declare @keyWord nvarchar(50),@index int;
select @index=0,@keyWord='';
set @index=Charindex(',',@targetKeyWords,1);
while @index>0
begin
set @keyWord=Substring(@targetKeyWords, 1, @index-1);
if Charindex(@keyWord, @sourceKeyWords,1)>0
return 1;
set @targetKeyWords=Substring(@targetKeyWords,@index+1,len(@targetKeyWords));
set @index=Charindex(',',@targetKeyWords,1);
end
return 0;
end
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐