SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


practical application of REVERSE function?


practical application of REVERSE function?

Author
Message
polkadot
polkadot
Ten Centuries
Ten Centuries (1K reputation)Ten Centuries (1K reputation)Ten Centuries (1K reputation)Ten Centuries (1K reputation)Ten Centuries (1K reputation)Ten Centuries (1K reputation)Ten Centuries (1K reputation)Ten Centuries (1K reputation)

Group: General Forum Members
Points: 1043 Visits: 1107
Will people kindly share practical applications of REVERSE sql function? I do not see any posts on this forum addressing it and am curious.
Thanks in advance.
laurie-789651
laurie-789651
SSChasing Mays
SSChasing Mays (616 reputation)SSChasing Mays (616 reputation)SSChasing Mays (616 reputation)SSChasing Mays (616 reputation)SSChasing Mays (616 reputation)SSChasing Mays (616 reputation)SSChasing Mays (616 reputation)SSChasing Mays (616 reputation)

Group: General Forum Members
Points: 616 Visits: 1272
They must have been thinking of something when they added it. Don't know what though...
roryp 96873
roryp 96873
Ten Centuries
Ten Centuries (1K reputation)Ten Centuries (1K reputation)Ten Centuries (1K reputation)Ten Centuries (1K reputation)Ten Centuries (1K reputation)Ten Centuries (1K reputation)Ten Centuries (1K reputation)Ten Centuries (1K reputation)

Group: General Forum Members
Points: 1024 Visits: 6604
I've used it to parse out address fields that have city, state and zip in one field. It's usually easier to look through it backwards with the idea that everything up to the first space will be the zip code, and going from there.
ColdCoffee
ColdCoffee
Hall of Fame
Hall of Fame (3.6K reputation)Hall of Fame (3.6K reputation)Hall of Fame (3.6K reputation)Hall of Fame (3.6K reputation)Hall of Fame (3.6K reputation)Hall of Fame (3.6K reputation)Hall of Fame (3.6K reputation)Hall of Fame (3.6K reputation)

Group: General Forum Members
Points: 3647 Visits: 5548
I use it mostly to parse out the file names from a long file path. Example:
DECLARE @FilePath VARCHAR(100)
SET @FilePath = 'C:\Users\abcd\AppData\Local\Temp\Temp.txt'
SELECT REVERSE(LEFT ( REVERSE(@FilePath) , CHARINDEX('\',REVERSE(@FilePath))))



Instead of finding the last backslash throu string splitters, i used combination of functions along with REVERSE to do the task..
Phil Parkin
Phil Parkin
SSCoach
SSCoach (18K reputation)SSCoach (18K reputation)SSCoach (18K reputation)SSCoach (18K reputation)SSCoach (18K reputation)SSCoach (18K reputation)SSCoach (18K reputation)SSCoach (18K reputation)

Group: General Forum Members
Points: 18123 Visits: 20388
ColdCoffee (7/30/2012)
I use it mostly to parse out the file names from a long file path. Example:
DECLARE @FilePath VARCHAR(100)
SET @FilePath = 'C:\Users\abcd\AppData\Local\Temp\Temp.txt'
SELECT REVERSE(LEFT ( REVERSE(@FilePath) , CHARINDEX('\',REVERSE(@FilePath))))



Instead of finding the last backslash throu string splitters, i used combination of functions along with REVERSE to do the task..


Generalisation - sometimes you'll find that a certain character in a string is repeated several times, and you want to extract the chunk of the string between the last occurrence of this character and the end of the string.

Without REVERSE(), this would be quite involved. ColdCoffee's solution shows how easy it is with REVERSE().


Help us to help you. For better, quicker and more-focused answers to your questions, consider following the advice in this link.

If the answer to your question can be found with a brief Google search, please perform the search yourself, rather than expecting one of the SSC members to do it for you.

Please surround any code or links you post with the appropriate IFCode formatting tags. It helps readability a lot.
Luis Cazares
Luis Cazares
SSCoach
SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)

Group: General Forum Members
Points: 16192 Visits: 19059
You can use it to check if 2 phrases are palindromes.
Just kidding.


Luis C.
General Disclaimer:
Are you seriously taking the advice and code from someone from the internet without testing it? Do you at least understand it? Or can it easily kill your server?


How to post data/code on a forum to get the best help: Option 1 / Option 2
polkadot
polkadot
Ten Centuries
Ten Centuries (1K reputation)Ten Centuries (1K reputation)Ten Centuries (1K reputation)Ten Centuries (1K reputation)Ten Centuries (1K reputation)Ten Centuries (1K reputation)Ten Centuries (1K reputation)Ten Centuries (1K reputation)

Group: General Forum Members
Points: 1043 Visits: 1107
OK, so you reverse the expression, find the character you want, perform the operation, and then reverse the expression again to aright it.
I have seen such situations arise, I now realize. Thank you CC and everyone for the responses.
Sean Lange
Sean Lange
One Orange Chip
One Orange Chip (25K reputation)One Orange Chip (25K reputation)One Orange Chip (25K reputation)One Orange Chip (25K reputation)One Orange Chip (25K reputation)One Orange Chip (25K reputation)One Orange Chip (25K reputation)One Orange Chip (25K reputation)

Group: General Forum Members
Points: 25783 Visits: 17509
Luis Cazares (7/30/2012)
You can use it to check if 2 phrases are palindromes.
Just kidding.



create function IsPalindrome(@String1 varchar(100), @String2 varchar(100))
returns table
return
(
select Case when @String1 = REVERSE(@String2) then 1 else 0 end as IsPalindrome
)

go

with cte (string1, string2)
as
(
Select 'racecar', 'racecar' union all
select 'racetruck', 'racetruck'
)

select *
from cte
cross apply dbo.IsPalindrome(string1, string2)



:-D

_______________________________________________________________

Need help? Help us help you.

Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.

Need to split a string? Try Jeff Modens splitter.

Cross Tabs and Pivots, Part 1 – Converting Rows to Columns
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs
Understanding and Using APPLY (Part 1)
Understanding and Using APPLY (Part 2)
Luis Cazares
Luis Cazares
SSCoach
SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)

Group: General Forum Members
Points: 16192 Visits: 19059
Thanks Sean, but I was joking with this because I'm not sure palindromes count as a "practical application".


Luis C.
General Disclaimer:
Are you seriously taking the advice and code from someone from the internet without testing it? Do you at least understand it? Or can it easily kill your server?


How to post data/code on a forum to get the best help: Option 1 / Option 2
polkadot
polkadot
Ten Centuries
Ten Centuries (1K reputation)Ten Centuries (1K reputation)Ten Centuries (1K reputation)Ten Centuries (1K reputation)Ten Centuries (1K reputation)Ten Centuries (1K reputation)Ten Centuries (1K reputation)Ten Centuries (1K reputation)

Group: General Forum Members
Points: 1043 Visits: 1107
when I said thanks to you, Luis, it was for the relationship advice, not the palindrome idea.
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search