Experts Exchange Solution brought to you by
"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.
This course teaches how to install and configure Windows Server 2012 R2. It is the first step on your path to becoming a Microsoft Certified Solutions Expert (MCSE).
with rev (length, newstring, oldstring)
select 0, cast ('' as varchar (200)), 'Some String' FROM sysibm.sysdummy1
newstring || case when length (oldstring) > 0 then right (oldstring, 1) else '' end,
left (oldstring, length (oldstring) - 1)
where oldstring <> ''
select * from rev r
where r.length = (select max(length) from rev);
Open in new window
Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.
CREATE FUNCTION Reverse (
modifies sql data
set option dbgview = *source
-- Scratch variables used for processing
DECLARE outputString VARCHAR(100);
DECLARE stringLength INT;
DECLARE loopCounter INT;
DECLARE charAtPos VARCHAR(1);
-- If the incoming string is NULL, return NULL
IF (inString IS NULL) THEN
-- Initialize the scratch variables
SET outputString = '';
SET stringLength = LENGTH(inString);
SET loopCounter = stringLength;
-- Loop over the string
WHILE (loopCounter >= 0) DO
-- Append a single character off the string
SET outputString = outputString || SUBSTRING (inString, loopCounter, 1);
SET loopCounter = loopCounter - 1;
-- Return the final output
if (outputString = '') then
From novice to tech pro — start learning today.
Members can enroll in this course at no extra cost.