如何提取两个字符串中相同的特定的字段,再加100分

linkyou 2005-03-11 01:52:26
function f_mergme(@U_ID int,@charater varchar(10))
returns varchar(8000)
as
begin
declare @s nvarchar(4000)
set @s=''
select @s=@s+@charater+s
from(
select top 100 percent
s=substring(a.R_MOdule,b.id,charindex(@charater,a.R_MOdule+@charater,b.id)-b.id)
from tb a,序数表 b
where a.U_ID=@U_ID and b.id<=len(a.R_MOdule) and substring -----将原来---的4改为@U_ID
(@charater+a.R_MOdule,b.id,1)=@charater
group by substring(a.R_MOdule,b.id,charindex(@charater,a.R_MOdule+@charater,b.id)-b.id)
having count(*)=(select count(*) from tb where U_ID=@U_ID) -----将原-----来的4改为@U_ID
order by min(id))a
return(stuff(@s,1,1,'')
)
end
函数如上,请问是什么原理呢
...全文
183 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
zjcxc 元老 2005-03-11
  • 打赏
  • 举报
回复
select top 100 percent
s=substring(a.R_MOdule,b.id,charindex(@charater,a.R_MOdule+@charater,b.id)-b.id)
from tb a,序数表 b
where a.U_ID=@U_ID and b.id<=len(a.R_MOdule) and substring -----将原来---的4改为@U_ID
(@charater+a.R_MOdule,b.id,1)=@charater

是分拆处理部分,a.R_MOdule你可以先用一个固定的字符串去代替,这样理解方便
原理就是将要分拆的字符串逐字截取,每个字一条记录,然后判断当前取的字符是否是,如果是,则取这条记录,并且截取自该位置(b.id)之后的第一个,的位置-开始位置(b.id)得到两个,之间的数据部分
如果当前记录所在的字符不是,丢弃此记录
Softlee81307 2005-03-11
  • 打赏
  • 举报
回复
這好像是zxjh 老大的 函數, 等他來回答吧

34,590

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server相关内容讨论专区
社区管理员
  • 基础类社区
  • 二月十六
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧