sqlserver 字符串分拆 语句
(编辑:jimmy 日期: 2024/11/13 浏览:2)
复制代码 代码如下:
-->Title:生成測試數據
-->Author:wufeng4552
-->Date :2009-09-21 09:02:08
if object_id('f_split')is not null drop function f_split
go
create function f_split
(
@s varchar(8000), --待分拆的字符串
@split varchar(10) --数据分隔符
)returns table
as
return
(
select substring(@s,number,charindex(@split,@s+@split,number)-number)as col
from master..spt_values
where type='p' and number<=len(@s+'a')
and charindex(@split,@split+@s,number)=number
)
go
select * from dbo.f_split('11,2,3',',')
/*
col
----
11
2
3
(3 個資料列受到影響)
*/