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
 General SQL Server Forums
 New to SQL Server Programming
 reverse script

Author  Topic 

pnpsql
Posting Yak Master

246 Posts

Posted - 2011-07-12 : 04:34:59
pls let me know how can i reverse a string without using reverse function..is it possible ..


challenge everything

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2011-07-12 : 04:38:42
Sounds like homework.
Why should someone do that without using REVERSE()...


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

uberman
Posting Yak Master

159 Posts

Posted - 2011-07-12 : 05:45:20
Start at the last character and work backwards?
Go to Top of Page

pnpsql
Posting Yak Master

246 Posts

Posted - 2011-07-12 : 08:05:29
BUT HOW??


challenge everything
Go to Top of Page

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2011-07-12 : 08:16:07
http://www.sqlservercentral.com/Forums/Topic697178-23-3.aspx#bm1112955



No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

Seventhnight
Master Smack Fu Yak Hacker

2878 Posts

Posted - 2011-07-12 : 08:23:03
This must be an interview or test question out there somewhere...

Corey

I Has Returned!!
Go to Top of Page

pnpsql
Posting Yak Master

246 Posts

Posted - 2011-07-12 : 08:25:26
yes ...u r right

challenge everything
Go to Top of Page

pnpsql
Posting Yak Master

246 Posts

Posted - 2011-07-12 : 09:11:03
THAT SHOULD BE DONE WITHOUT LOOP...


challenge everything
Go to Top of Page

robvolk
Most Valuable Yak

15732 Posts

Posted - 2011-07-12 : 09:33:22
And for our next trick, we will open a can of food without a can opener! Or even touching the can! And without using explosives!

If this is an interview question, here's your answer: "I'll use the built-in REVERSE() function, thanks, because that's what it's there for, and any other method is wasteful of time and resources, and since you'll be paying me, your money."
Go to Top of Page

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2011-07-12 : 09:34:59
quote:
Originally posted by robvolk

And for our next trick, we will open a can of food without a can opener! Or even touching the can! And without using explosives!

If this is in interview question, here's your answer: "I'll use the built-in REVERSE() function, thanks, because that's what it's there for, and any other method is wasteful of time and resources, and since you'll be paying me, your money."


I've pushed the "I like"-Button!


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

pnpsql
Posting Yak Master

246 Posts

Posted - 2011-07-12 : 09:44:01
BUT WHEN IT IS CHALLENGE HOW CAN U DEAL THIS....


challenge everything
Go to Top of Page

GilaMonster
Master Smack Fu Yak Hacker

4507 Posts

Posted - 2011-07-12 : 09:47:38
Don't shout at us.

If someone's telling you to do that, you tell him that it's a silly thing to do. There is no point in figuring out alternatives to built in functions. The built in functions are there. They work efficiently. There is no good reason to go and reimplement them other than to waste time and money.

--
Gail Shaw
SQL Server MVP
Go to Top of Page

robvolk
Most Valuable Yak

15732 Posts

Posted - 2011-07-12 : 09:49:58
It's a stupid challenge, and stop using all caps. Even if you found a solution you'd never use it because it's far less efficient, especially in SQL Server.

If you want a challenge that will actually make you a better programmer: http://projecteuler.net/
Go to Top of Page

robvolk
Most Valuable Yak

15732 Posts

Posted - 2011-07-12 : 09:57:40
Even the people running the challenge say you should use the REVERSE() function: http://beyondrelational.com/blogs/tc/archive/2009/04/22/tsql-challenge-3.aspx
Go to Top of Page

Michael Valentine Jones
Yak DBA Kernel (pronounced Colonel)

7020 Posts

Posted - 2011-07-12 : 10:04:14
What is the use of having someone else solve the problem for you? The idea of a challenge is that it is a problem for you to solve.

If you're not up to the challenge, well I guess you failed.




CODO ERGO SUM
Go to Top of Page

pnpsql
Posting Yak Master

246 Posts

Posted - 2011-07-12 : 23:41:33
hi michael , we are here to help each other , every question that is put there by anyone is a challenge for him , after trying his best anyone need to take help. so don't be rude if u r a here to help ..u should keep silence when u have no answer...

thanks


challenge everything
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2011-07-13 : 01:03:58
The people organizing the challenge may be able to spot the solution is way to complicated and above normal standard for OP?
DECLARE	@Sample VARCHAR(100) = 'PVM ,nossraL reteP'

SELECT @Sample AS Original,
REVERSE(@Sample) AS TheSimpleWay,
CAST(Data AS VARCHAR(100)) AS Reversed
FROM (
SELECT SUBSTRING(@Sample, DATALENGTH(@Sample) - Number, 1)
FROM master..spt_values
WHERE Type = 'P'
AND Number BETWEEN 0 AND DATALENGTH(@Sample) - 1
ORDER BY Number
FOR XML PATH(''),
TYPE
) AS d(Data)



N 56°04'39.26"
E 12°55'05.63"
Go to Top of Page

elwoos
Master Smack Fu Yak Hacker

2052 Posts

Posted - 2011-07-13 : 06:08:08
quote:
Originally posted by pnpsql

hi michael , we are here to help each other , every question that is put there by anyone is a challenge for him , after trying his best anyone need to take help. so don't be rude if u r a here to help ..u should keep silence when u have no answer...



Michael has said nothing rude, he simply made an observation. You say you have tried your best but have posted no evidence whatsoever of that here, unless by your best you mean posting a question on a forum! If you had shown what you have tried so far you may have got a more sympathetic response.

-----------

What color do you want that database?
Go to Top of Page

Michael Valentine Jones
Yak DBA Kernel (pronounced Colonel)

7020 Posts

Posted - 2011-07-13 : 13:43:54
quote:
Originally posted by pnpsql

hi michael , we are here to help each other , every question that is put there by anyone is a challenge for him , after trying his best anyone need to take help. so don't be rude if u r a here to help ..u should keep silence when u have no answer...

thanks


challenge everything



The challenge obviously has no practical real world use, so I have to assume it is an intellectual challenge meant to test your problem solving ability.

Since you can’t solve the problem, I see no reason for someone else to answer it for you.














CODO ERGO SUM
Go to Top of Page
   

- Advertisement -