--分拆可以使用临时表
declare @s varchar(4000)
set @s='-1;-1;0;0;0;'
select top 8000 id=identity(int,1,1) into # from syscolumns a, syscolumns b
select substring(@s,id,charindex(';',@s+';',id)-id)
from #
where substring(';'+@s,id,1)=';'
and id<len(@s)
drop table #
/*
功能:实现split功能的函数
*/
create function fn_split
(
@inputstr varchar(8000),
@seprator varchar(10)
)
returns @temp table (a varchar(200))
as
begin
declare @i int
set @inputstr = rtrim(ltrim(@inputstr))
set @i = charindex(@seprator, @inputstr)
while @i >= 1
begin
insert @temp values(left(@inputstr, @i - 1))
set @inputstr = substring(@inputstr, @i + 1, len(@inputstr) - @i)
set @i = charindex(@seprator, @inputstr)
end
if @inputstr <> '/'
insert @temp values(@inputstr)
return
end
go
--调用
select * from dbo.fn_split('-1;-1;0;0;0;',';')
--结果
/*
-1
-1
0
0
0
*/