Hi I am trying to reverse string word by word suppose I have input
- I/P : 'My Name is sachin'
- O/P : 'sachin is Name My'
I have created this code but it keeps running:
declare @I varchar(20)
declare @O varchar(20)
declare @T varchar(20)
set @I='My Name is sachin'
set @O=''
while CHARINDEX(' ',@I)>0
begin
set @T=substring(REVERSE(@I),1,charindex(' ',REVERSE(@I))-1)
set @O=@O+' '+REVERSE(@T)
set @I=reverse(STUFF(REVERSE(@I),1,CHARINDEX(' ',REVERSE(@I))-1,''))
end
Anyone can help me out?