欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

SQL实用技巧:如何分割字符串

程序员文章站 2022-12-21 14:30:25
create function f_split(@c varchar(2000),@split varchar(2)) returns @t table(col varchar(20)) as begin while(charindex(@split,@c)<>0) begin insert @t( ......
create function f_split(@c varchar(2000),@split varchar(2)) 
returns @t table(col varchar(20))
as
begin

while(charindex(@split,@c)<>0)
begin
insert @t(col) values (substring(@c,1,charindex(@split,@c)-1))
set @c = stuff(@c,1,charindex(@split,@c),'')
end
insert @t(col) values (@c)
return
end
go

select * from dbo.f_split('dfkd,dfdkdf,dfdkf,dffjk',',')

drop function f_split