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


Reverse string without built in functions


Reverse string without built in functions

Author
Message
RBarryYoung
RBarryYoung
SSC Guru
SSC Guru (80K reputation)SSC Guru (80K reputation)SSC Guru (80K reputation)SSC Guru (80K reputation)SSC Guru (80K reputation)SSC Guru (80K reputation)SSC Guru (80K reputation)SSC Guru (80K reputation)

Group: General Forum Members
Points: 80620 Visits: 9519
This is actually from Jacob Sebastiens Challenge #3, where the actual rules were: "Write a single query that can reverse the strings in this column without using the REVERSE() function".

-- RBarryYoung, (302)375-0451 blog: MovingSQL.com, Twitter: @RBarryYoung
Proactive Performance Solutions, Inc.
"Performance is our middle name."
pshvets
pshvets
SSC Eights!
SSC Eights! (974 reputation)SSC Eights! (974 reputation)SSC Eights! (974 reputation)SSC Eights! (974 reputation)SSC Eights! (974 reputation)SSC Eights! (974 reputation)SSC Eights! (974 reputation)SSC Eights! (974 reputation)

Group: General Forum Members
Points: 974 Visits: 154
My question is not a homework question. Smile
My background is BI Development on Oracle, Teradata, Unix platforms. I am simply learning MS SQL Server and T-SQL.

And thanks for all your help!

Pit.
Michael Valentine Jones
Michael Valentine Jones
SSC-Dedicated
SSC-Dedicated (36K reputation)SSC-Dedicated (36K reputation)SSC-Dedicated (36K reputation)SSC-Dedicated (36K reputation)SSC-Dedicated (36K reputation)SSC-Dedicated (36K reputation)SSC-Dedicated (36K reputation)SSC-Dedicated (36K reputation)

Group: General Forum Members
Points: 36134 Visits: 11933
Maybe you should learn to use what is available in SQL Server, like REVERSE, instead of spending time duplicating what is already available.
GSquared
GSquared
SSC Guru
SSC Guru (139K reputation)SSC Guru (139K reputation)SSC Guru (139K reputation)SSC Guru (139K reputation)SSC Guru (139K reputation)SSC Guru (139K reputation)SSC Guru (139K reputation)SSC Guru (139K reputation)

Group: General Forum Members
Points: 139959 Visits: 9731
Michael Valentine Jones (4/15/2009)
Maybe you should learn to use what is available in SQL Server, like REVERSE, instead of spending time duplicating what is already available.



Nah. One of the best ways to learn the tricky parts of any engineering tool (and programming languages are definitely engineering tools) is to work out how to do something without using a pre-built answer.

Nails and screws are awefully convenient, but it's fun and educational to build a wooden cabinet without using any. Take away wood glue also, and it's a challenge for even a good woodworker, and fun. And it teaches you techniques you can use in other applications that might be more practical.

- Gus "GSquared", RSVP, OODA, MAP, NMVP, FAQ, SAT, SQL, DNA, RNA, UOI, IOU, AM, PM, AD, BC, BCE, USA, UN, CF, ROFL, LOL, ETC
Property of The Thread

"Nobody knows the age of the human race, but everyone agrees it's old enough to know better." - Anon
jcrawf02
jcrawf02
SSChampion
SSChampion (10K reputation)SSChampion (10K reputation)SSChampion (10K reputation)SSChampion (10K reputation)SSChampion (10K reputation)SSChampion (10K reputation)SSChampion (10K reputation)SSChampion (10K reputation)

Group: General Forum Members
Points: 10916 Visits: 19324
GSquared (4/16/2009)
Michael Valentine Jones (4/15/2009)
Maybe you should learn to use what is available in SQL Server, like REVERSE, instead of spending time duplicating what is already available.



Nah. One of the best ways to learn the tricky parts of any engineering tool (and programming languages are definitely engineering tools) is to work out how to do something without using a pre-built answer.

Nails and screws are awefully convenient, but it's fun and educational to build a wooden cabinet without using any. Take away wood glue also, and it's a challenge for even a good woodworker, and fun. And it teaches you techniques you can use in other applications that might be more practical.


Pshaw! That's no challenge, just use duct tape.

---------------------------------------------------------
How best to post your question
How to post performance problems
Tally Table:What it is and how it replaces a loop

"stewsterl 80804 (10/16/2009)I guess when you stop and try to understand the solution provided you not only learn, but save yourself some headaches when you need to make any slight changes."
GSquared
GSquared
SSC Guru
SSC Guru (139K reputation)SSC Guru (139K reputation)SSC Guru (139K reputation)SSC Guru (139K reputation)SSC Guru (139K reputation)SSC Guru (139K reputation)SSC Guru (139K reputation)SSC Guru (139K reputation)

Group: General Forum Members
Points: 139959 Visits: 9731
jcrawf02 (4/17/2009)
GSquared (4/16/2009)
Michael Valentine Jones (4/15/2009)
Maybe you should learn to use what is available in SQL Server, like REVERSE, instead of spending time duplicating what is already available.



Nah. One of the best ways to learn the tricky parts of any engineering tool (and programming languages are definitely engineering tools) is to work out how to do something without using a pre-built answer.

Nails and screws are awefully convenient, but it's fun and educational to build a wooden cabinet without using any. Take away wood glue also, and it's a challenge for even a good woodworker, and fun. And it teaches you techniques you can use in other applications that might be more practical.


Pshaw! That's no challenge, just use duct tape.


Well, I've found that when you try to use duct tape to reverse a character string, it leaves bits of glue all over your hard drives, and that's a bit of a problem...

- Gus "GSquared", RSVP, OODA, MAP, NMVP, FAQ, SAT, SQL, DNA, RNA, UOI, IOU, AM, PM, AD, BC, BCE, USA, UN, CF, ROFL, LOL, ETC
Property of The Thread

"Nobody knows the age of the human race, but everyone agrees it's old enough to know better." - Anon
Vijaya Kadiyala
Vijaya Kadiyala
SSCertifiable
SSCertifiable (5.5K reputation)SSCertifiable (5.5K reputation)SSCertifiable (5.5K reputation)SSCertifiable (5.5K reputation)SSCertifiable (5.5K reputation)SSCertifiable (5.5K reputation)SSCertifiable (5.5K reputation)SSCertifiable (5.5K reputation)

Group: General Forum Members
Points: 5535 Visits: 409
check out the below link, This will give you the function to reverse a string with out using REVERSE.

http://blog.sqlauthority.com/2007/05/01/sql-server-user-defined-functions-udf-to-reverse-string-udf_reversestring/

I always prefer to use existing functions, if they are available instead of duplicating the function.. but again on the other had if we try to duplicate the logic it will increase our programming capabilities :;-)

I am confusingHehe

Thanks -- Vijaya Kadiyala
www.dotnetvj.com
SQL Server Articles For Beginers



RBarryYoung
RBarryYoung
SSC Guru
SSC Guru (80K reputation)SSC Guru (80K reputation)SSC Guru (80K reputation)SSC Guru (80K reputation)SSC Guru (80K reputation)SSC Guru (80K reputation)SSC Guru (80K reputation)SSC Guru (80K reputation)

Group: General Forum Members
Points: 80620 Visits: 9519
jcrawf02 (4/17/2009)
GSquared (4/16/2009)
Michael Valentine Jones (4/15/2009)
Maybe you should learn to use what is available in SQL Server, like REVERSE, instead of spending time duplicating what is already available.



Nah. One of the best ways to learn the tricky parts of any engineering tool (and programming languages are definitely engineering tools) is to work out how to do something without using a pre-built answer.

Nails and screws are awefully convenient, but it's fun and educational to build a wooden cabinet without using any. Take away wood glue also, and it's a challenge for even a good woodworker, and fun. And it teaches you techniques you can use in other applications that might be more practical.


Pshaw! That's no challenge, just use duct tape.
Hmm, interesting idea... :-)

-- RBarryYoung, (302)375-0451 blog: MovingSQL.com, Twitter: @RBarryYoung
Proactive Performance Solutions, Inc.
"Performance is our middle name."
ChrisM@Work
ChrisM@Work
SSC Guru
SSC Guru (97K reputation)SSC Guru (97K reputation)SSC Guru (97K reputation)SSC Guru (97K reputation)SSC Guru (97K reputation)SSC Guru (97K reputation)SSC Guru (97K reputation)SSC Guru (97K reputation)

Group: General Forum Members
Points: 97388 Visits: 20698
Pinal Dave's reverse function has this code in it:
RETURN (REVERSE(@StringToReverse))

“Write the query the simplest way. If through testing it becomes clear that the performance is inadequate, consider alternative query forms.” - Gail Shaw

For fast, accurate and documented assistance in answering your questions, please read this article.
Understanding and using APPLY, (I) and (II) Paul White
Hidden RBAR: Triangular Joins / The "Numbers" or "Tally" Table: What it is and how it replaces a loop Jeff Moden
Exploring Recursive CTEs by Example Dwain Camps
Michael Valentine Jones
Michael Valentine Jones
SSC-Dedicated
SSC-Dedicated (36K reputation)SSC-Dedicated (36K reputation)SSC-Dedicated (36K reputation)SSC-Dedicated (36K reputation)SSC-Dedicated (36K reputation)SSC-Dedicated (36K reputation)SSC-Dedicated (36K reputation)SSC-Dedicated (36K reputation)

Group: General Forum Members
Points: 36134 Visits: 11933
OK, as long as we are doing useless SQL, I want to add numbers together without using any Arithmetic, Logical, Assignment, String, Bitwise, or Unary Operators or any Mathematical or Aggregate Functions.
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