How to split string in Sql Server

Akshayblevel
Posted by Akshayblevel under Sql Server category on | Points: 40 | Views : 1566
DECLARE @Pos INT
DECLARE @NextPos INT
DECLARE @String VARCHAR(50)
DECLARE @Delimiter VARCHAR(50)

SET @String ='.net,funda,.com'
SET @Delimiter = ','
SET @String = @String + @Delimiter
SET @Pos = charindex(@Delimiter,@String)

WHILE (@pos <> 0)
BEGIN
SELECT substring(@String,1,@Pos - 1)
SET @String = substring(@String,@pos+1,len(@String))
SET @pos = charindex(@Delimiter,@String)
END

Comments or Responses

Posted by: Srilu.Nayini577 on: 8/6/2012 Level:Starter | Status: [Member] | Points: 10
good approach
Posted by: Deviprasads on: 12/12/2012 Level:Starter | Status: [Member] | Points: 10
This solution helped me today..

Thanks,
Deviprasad

Login to post response