Procedure for Split the words in SQL Sever
Here it is the procedure to Split the words using comma seperator. still you can use different character for split instead of comma(','). Here i m using 'E,l,e,p,h,a,n,t' as word with comma characters.
so the output should be 'E','l','e','p','h','a','n','t'.

Output of this query would be,
so the output should be 'E','l','e','p','h','a','n','t'.
Declare @name as varchar(20)Declare @i as intDeclare @char as charDeclare @word as varchar(20)select @name='E,l,e,p,h,a,n,t'set @word=''set @i=1while @i<=len(@name) begin set @char=substring(@name,@i,1) if @char<> ','beginset @word=@word+@charendelse if (@char=',' and @i<>len(@name))beginprint @wordset @word=''end---Print the last wordif @i=len(@name)beginprint @wordendset @i=@i+1end

Output of this query would be,
Comments
Post a Comment