--创建函数
create function f_split(@str varchar(8000))
returns @tb table(num int)
as
begin
while charindex(',',@str)>0
begin
insert @tb
select left(@str,charindex(',',@str)-1) set @str=stuff(@str,1,charindex(',',@str),'')
end
insert @tb select @str
return
end
go--测试
declare @s varchar(100)
select @s='1,2,3,4,5,6,7,8'
select * from f_split(@s)--结果
/*
num
-----------
1
2
3
4
5
6
7
8(所影响的行数为 8 行)
*/
create function f_split(@str varchar(8000))
returns @tb table(num int)
as
begin
while charindex(',',@str)>0
begin
insert @tb
select left(@str,charindex(',',@str)-1) set @str=stuff(@str,1,charindex(',',@str),'')
end
insert @tb select @str
return
end
go--测试
declare @s varchar(100)
select @s='1,2,3,4,5,6,7,8'
select * from f_split(@s)--结果
/*
num
-----------
1
2
3
4
5
6
7
8(所影响的行数为 8 行)
*/
再问个问题
sql server不支持类似这种数据的直接提取吗?
有没有更直接的方法,不用写函数什么的..