sqlserver分隔字符串,查找父类下所有子类,删除重复字符串,计算一字符串在别一字符中出现的次数
来源:互联网 发布:土建施工员软件 编辑:程序博客网 时间:2024/06/06 10:47
/*dnt下面分隔字符串函数*/
create FUNCTION [dnt_split]
(
@splitstring NVARCHAR(4000),
@separator CHAR(1) = ','
)
RETURNS @splitstringstable TABLE
(
[item] NVARCHAR(200)
)
AS
BEGIN
DECLARE @currentindex INT
DECLARE @nextindex INT
DECLARE @returntext NVARCHAR(200)
SELECT @currentindex=1
WHILE(@currentindex<=datalength(@splitstring)/2)
BEGIN
SELECT @nextindex=charindex(@separator,@splitstring,@currentindex)
IF(@nextindex=0 OR @nextindex IS NULL)
SELECT @nextindex=datalength(@splitstring)/2+1
SELECT @returntext=substring(@splitstring,@currentindex,@nextindex-@currentindex)
INSERT INTO @splitstringstable([item])
VALUES(@returntext)
SELECT @currentindex=@nextindex+1
END
RETURN
END
/*查找分类下面所有子类*/
create function f_child(@typeId)
returns @re table(typeId int,Level int)
as
begin
declare @l int
set @l=0
insert @re select @typeId,@l
while @@rowcount>0
begin
set @l=@l+1
insert @re select a.typeid,@l
from product_type a join @re b on a.fatherId=b.typeId
where b.level=@l-1
end
return
end
/*删除以逗号分隔的重复字符串*/
create function DeleteRepeatStrs
(@strs varchar(100))
returns varchar(100)
as
begin
declare @noRepeatStr varchar(100)
declare @index int
set @noRepeatStr=''
declare @id varchar(10)
declare repeatCursor cursor for select * from dnt_split(@strs,',')
open repeatCursor
fetch next from repeatCursor into @id
while @@fetch_status=0
begin
select @index=charindex(@id,@noRepeatStr,0)
if @index=0
begin
set @noRepeatStr=@noRepeatStr+@id+','
end
fetch next from repeatCursor into @id
end
set @noRepeatStr=substring(@noRepeatStr,1,len(@noRepeatStr)-1)
close repeatCursor
deallocate repeatCursor
return @noRepeatStr
end
/*计算参数2在参数1中出现的次数*/
ALTER function cisum(@thestr varchar(1000),@searchstr varchar(100))
returns smallint
as
begin
declare @a smallint,@b smallint
set @a=0
set @b=1
while @b<=len(@thestr)
begin
if substring(@thestr,@b,len(@searchstr))=@searchstr begin set @a=@a+1 end
set @b=@b+1
end
return @a
end
- sqlserver分隔字符串,查找父类下所有子类,删除重复字符串,计算一字符串在别一字符中出现的次数
- php统计所有字符在字符串中出现的次数
- php统计所有字符在字符串中出现的次数
- 删除字符串中所有重复出现的字符
- C++实现删除字符串中所有重复出现的字符
- C++查找字符在字符串中出现的次数
- 计算字符串中出现字符的次数
- 计算字符串中出现字符的次数
- ORACLE计算字符在字符串中出现的次数
- 计算字符在字符串中出现的次数
- [SQL]计算字符在字符串中出现的次数
- ORACLE计算字符在字符串中出现的次数
- 计算字符在字符串中出现的次数
- 计算特定字符在字符串中出现的次数
- 获取一字符串中,每一个字符出现的次数。
- 找出字符串中所有重复的字符及其重复次数
- [sqlserver]在text类型字段中查找字符串出现次数
- 如果字符串一的所有字符按其在字符串中的顺序出现在另外一个字符串二中,则字符串一称之为字符串二的子串。
- 构造方法以及对象初始化过程
- WM_DRAWITEM消息
- 龙芯取得MIPS授权是件好事
- 很好的一篇文章 如果让我重做一次研究生 王汎森
- 一张图分出你是用左脑还是右脑
- sqlserver分隔字符串,查找父类下所有子类,删除重复字符串,计算一字符串在别一字符中出现的次数
- ASP.NET跨页面传值技巧总结
- PF_PACKET 设备层编程接口
- (转)QT事件机制
- 制作IE扩展
- MEASUREITEMSTRUCT
- WinMain函数参数介绍
- 大学老师:现在的毕业生让我们很崩溃 很无奈
- Windows Server 2003 IIS 的日期格式(转)