因查詢統計需要,今天早上在SQLSERVER裡寫了一個類似於Split的函數,如下China It Power . Commll6Tgl
create function f_split(@SourceSql varchar(8000),@StrSeprate varchar(10))
returns @temp table(a varchar(100))
--實現split功能 的函數
--date :2005-4-20
--Author :Domino
as
begin
declare @i int
set @SourceSql=rtrim(ltrim(@SourceSql))
set @i=charindex(@StrSeprate,@SourceSql)
while @i>=1
begin
insert @temp values(left(@SourceSql,@i-1))
set @SourceSql=substring(@SourceSql,@i+1,len(@SourceSql)-@i)
set @i=charindex(@StrSeprate,@SourceSql)
end
if @SourceSql<>'\'
insert @temp values(@SourceSql)
return
end
China It Power . Commll6Tgl
用法:select * from dbo.f_split('A:B:C:D:E',':')China