Create Function [dbo].[SplitString](@String varchar(8000), @Delimiter char(1))
returns @temptable TABLE (items varchar(8000),id int)
as
begin
declare @idx int
declare @idy int
declare @slice varchar(8000)
set @idy=1
select @idx = 1
if len(@String)<1 or @String is null return
while @idx!= 0
begin
set @idx = charindex(@Delimiter,@String)
if @idx!=0
set @slice = left(@String,@idx - 1)
else
set @slice = @String
if(len(@slice)>0)
insert into @temptable(id,Items) values(@idy, @slice)
set @idy=@idy+1
set @String = right(@String,len(@String) - @idx)
if len(@String) = 0 break
end
return
end

Programming is fun and interesting. As you all know, sometime we programmers stucks in the middle way of coding without getting a solution. Blogs like this will help us to find a path to solve our problems. The contents of this blog are the solutions that I found by myself and from other sources. Sharing such solutions is also interesting. Thank you!
Wednesday, March 18, 2015
Split string using delimiter in sql server
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment