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