mssql,charindex,substring,split,分割,函数
2008-07-01 11:56 Virus-BeautyCode 阅读(1144) 评论(2) 编辑 收藏 举报 create function fsplit(@str varchar(8000))
returns @tb table(ch varchar(8000))
as
begin
declare @i int
set @str=@str+','
set @i=charindex(',',@str)
while @i>0
begin
insert into @tb values(left(@str,@i-1))
set @str=substring(@str,@i+1,8000)
set @i=charindex(',',@str)
end
return
end
go
--调用此函数进行分拆
select * from dbo.fsplit('sdafj,sadf;j;aslfi3a,a,a,b')
go
--删除函数
drop function fsplit
returns @tb table(ch varchar(8000))
as
begin
declare @i int
set @str=@str+','
set @i=charindex(',',@str)
while @i>0
begin
insert into @tb values(left(@str,@i-1))
set @str=substring(@str,@i+1,8000)
set @i=charindex(',',@str)
end
return
end
go
--调用此函数进行分拆
select * from dbo.fsplit('sdafj,sadf;j;aslfi3a,a,a,b')
go
--删除函数
drop function fsplit