sqlserver split函数


/*
获取字符串数组的 Table www.cnblogs.com/xqhppt/p/4377757.html
*/

if exists (select 1 from sysobjects where id = object_id('split' ))
drop Function split
go
CREATE function split(
@SourceSql varchar (max),
@StrSeprate varchar (10)
)
returns @temp table( F1 varchar (100))
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
GO

 

 

----------------------------------------------------test-------------------------------------------------------------------------------------------------------------------
declare @str nvarchar(max)
set @str='' --先设置值,否则Null+任何东西都是Null
declare @i int
set @i=1
while @i<1000
begin
set @str=@str+cast(@i as varchar(500))+','
--print @str
set @i=@i+1
end
select @str

declare @start datetime
declare @end datetime
set @start=getdate();
select * from split(@str,',')
set @end=GETDATE();
print @start
print @end
print @end-@start

 

From:http://www.cnblogs.com/xuejianxiyang/p/7025929.html


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM