Splitting Website URL in TSQL
Recently I was involved in a task of splitting the URL’s and generating some reference based on them. I started looking around on google and found this function Split from http://www.otecode.com. This Table Valued function returns a list of substring based on the literal you specify as parameter
create function [fn_Split] ( @text varchar(8000) ,@Delimiter varchar(20) = ' ' ) returns @Strings Table ( position int identity primary key ,value varchar(8000) ) as Begin Declare @index int set @index = -1 while ( Len(@text) > 0 ) Begin set @Index = charIndex(@delimiter,@text) if (@index = 0) and (len(@text) > 0) Begin Insert into @Strings values(@text) Break End if (@Index > 1) Begin Insert into @Strings values (Left (@text , @index - 1)) set @text = right (@text , (len(@text) - @index)) End Else set @text = Right(@text , (len(@text) - @index)) End Return end
So this is how i used the Split function

Using Function Split
The Results

The Results after Splitting


