现在的位置: 首页 > 综合 > 正文

sql字符分割函数

2011年02月21日 ⁄ 综合 ⁄ 共 429字 ⁄ 字号 评论关闭
create function f_split(@col1 varchar(8000),@col varchar(2))
returns @t table(col varchar(50))
as
begin
declare @i int
set @i=len(@col1+'a')-2
while charindex(@col,@col1)>0
begin
insert @t values (left(@col1,charindex(',',@col1)-1))
select @col1=stuff(@col1,1,charindex(',',@col1),'')
end
insert @t values (@col1)
return
end
go

declare @s varchar(8000)
set @s='1234567891,1234567892,1234567893,1234567894'

insert tb(字段)
select * from dbo.f_split(@s,',')

drop function f_split

抱歉!评论已关闭.