复制代码 代码如下:
–>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 個資料列受到影響)
*/