Procedure for Split the words in SQL Sever

Posted By  youngmurukan On 12 Apr 2010 10:04:19
emailbookmarkadd commentsprint
No of Views:831
Bookmarked:0 times
Votes:0 times

Introduction

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'.

Declare @name as varchar(20)
Declare @i as int
Declare @char as char
Declare @word as varchar(20)
select @name='E,l,e,p,h,a,n,t'
set @word=''
set @i=1
while @i<=len(@name) begin set @char=substring(@name,@i,1) if @char<> ','
begin
set @word=@word+@char
end
else if (@char=',' and @i<>len(@name))
begin
print @word
set @word=''
end
---Print the last word
if @i=len(@name)
begin
print @word
end
set @i=@i+1
end

 

Image Loading

Output

Image Loading

Thank you and hope this help.

Sign Up to vote for this article
Other popular Tips/Tricks
Comments
By:JohnBangoDate Of Posted:9/19/2011 7:27:14 AM
Re: Formula field in Crystal Report
Hi Author, Great article !!!!!!! quite entertained... please check out the following links for more details on formula field in crystal report ......... http://mindstick.com/Articles/ad1bda11-7a4c-4760-9df3-987f46b99029/?Formula%20Field%20in%20Crystal%20Report Thanks !!!!!
Leave a Reply
Title:
Display Name:
Email:
(not display in page for the security purphase)
Website:
Message:
Please refresh your screen using Ctrl+F5
If you can't read this number refresh your screen
Please input the anti-spam code that you can read in the image.
^ Scroll to Top