下表中,如何用sql查询出列1中有重复字符串的字段值,如“”张三三“”、“”李四四“”。备注:字段值随机,筛选出有重复字符串的字段记录就可以了,不需要统计次数等其他操作。
1 回答
翻过高山走不出你
TA贡献1875条经验 获得超3个赞
1:利用len函数
declare @a varchar(20)
set @a='adfarghbaaf'
select len(@a)- len(replace(@a,'a',''))
2:自定义一个函数
create function fn_str_times
(
@str varchar(1000),--原子符串
@indexstr varchar(20)--查找的字符
)
returns int
as
begin
declare @findlen int
declare @times int
set @findlen=LEN(@indexstr)
set @times=0
while(charindex(@indexstr,@str))>0
BEGIN
set @str=SUBSTRING(@str,CHARINDEX(@indexstr,@str)+@findlen,len(@str))
set @times=@times+1
end
return @times
end
select dbo.fn_str_times('adfarghbaaf','a')as 出现次数- 1 回答
- 0 关注
- 929 浏览
添加回答
举报
0/150
提交
取消
