Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 loop on string

Author  Topic 

vaibhavktiwari83
Aged Yak Warrior

843 Posts

Posted - 2010-02-25 : 04:37:04
I want to apply a loop on a string to get each character one by one...

Vabhav T

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2010-02-25 : 04:40:50
you want the char to return in rows ?



KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

senthil_nagore
Master Smack Fu Yak Hacker

1007 Posts

Posted - 2010-02-25 : 04:41:33
Try this!

declare @string varchar(50)
set @string='Testing'
while(len(@string)>0)
Begin
select left(@string,1)
set @string=right(@string,len(@string)-1)
End

Senthil.C
------------------------------------------------------
[Microsoft][ODBC SQL Server Driver]Operation canceled

http://senthilnagore.blogspot.com/
Go to Top of Page

vaibhavktiwari83
Aged Yak Warrior

843 Posts

Posted - 2010-02-25 : 04:45:15
Thanks a lot senthil...

Vabhav T
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2010-02-25 : 04:46:08
declare @string varchar(100)
set @string='this is my string'
select substring(@string,number,1) as single_character from master..spt_values
where type='p' and number between 1 and len(@string)

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

senthil_nagore
Master Smack Fu Yak Hacker

1007 Posts

Posted - 2010-02-25 : 04:46:25
Welcome! :)

Senthil.C
------------------------------------------------------
[Microsoft][ODBC SQL Server Driver]Operation canceled

http://senthilnagore.blogspot.com/
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2010-02-25 : 05:19:27
quote:
Originally posted by vaibhavktiwari83

I want to apply a loop on a string to get each character one by one...

Vabhav T


You have already used such a function here
http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=140365

Haven't you?

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -