A nice equivalent to the Split Function in T-SQL

CREATE FUNCTION [dbo].[fn_split]
(
    @sString nvarchar(2048),
    @cDelimiter nchar(1)
)
RETURNS @tParts TABLE ( part nvarchar(2048) )
AS
BEGIN
    if @sString is null return
    declare     @iStart int,
                @iPos int
    if substring( @sString, 1, 1 ) = @cDelimiter
    begin
        set     @iStart = 2
        insert into @tParts
        values( null )
    end
    else
        set     @iStart = 1
    while 1=1
    begin
        set     @iPos = charindex( @cDelimiter, @sString, @iStart )
        if @iPos = 0
                set     @iPos = len( @sString )+1
        if @iPos - @iStart > 0                 
                insert into @tParts
                values  ( substring( @sString, @iStart, @iPos-@iStart ))
        else
                insert into @tParts
                values( null )
        set     @iStart = @iPos+1
        if @iStart > len( @sString )
                break
    end
    RETURN

END
go
Tags
Comments
Write the first comment
Leave a trace
Name *
Email *
Website
Anti SPAM * Code (7 + 7) =
Leave me a comment *
 
All comments are subject to editorial review
Post being viewed right now
Item date: 28.06.2010
Views: 2063
Item date: 04.02.2009
Views: 1608
Item date: 11.04.2009
Views: 1858
Item date: 05.10.2009
Views: 81673
Item date: 07.03.2009
Views: 726
Item date: 09.09.2009
Views: 489
Item date: 19.07.2009
Views: 409
Item date: 08.04.2009
Views: 506
Item date: 20.07.2009
Views: 713
Item date: 19.07.2009
Views: 1087