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 2000 Forums
 SQL Server Development (2000)
 Reversing a word with parameter

Author  Topic 

ragh
Starting Member

34 Posts

Posted - 2002-10-18 : 07:10:23
How can i reverse a word or sentence that i input in parameter.
ex: if input is :
'Hello How Are you'
must be reversed as :
'you Are How Hello'

thats it just mail me the script to raghx_2000@yahoo.com

bye guys !


Ragh

Page47
Master Smack Fu Yak Hacker

2878 Posts

Posted - 2002-10-18 : 07:22:07
There are probably several ways to do this.

One way is to combine the Parsing CSV Values Into Multiple Rows article with the Using COALESCE to Build Comma-Delimited String article.


declare @csv varchar(100), @sep char(1), @result varchar(100)
select @csv = 'Hello How Are you', @sep = ' '

select
@result = coalesce(@result + ' ', '') + element
from (
select top 100 percent
nullif(substring(@sep+@csv+@sep,n,charindex(@sep,@sep+@csv+@sep,n)-n),'') as element
from
dbo.numbers
where
n<=datalength(@sep+@csv+@sep) and
n-datalength(@sep)>0 and
substring(@sep+@csv+@sep,n-datalength(@sep),datalength(@sep))=@sep and
charindex(@sep,@sep+@csv+@sep,n)-n>0
order by
n desc ) a

select @result

 


Jay White
{0}
Go to Top of Page
   

- Advertisement -