pshvets (4/14/2009)
Hmmm...Does it mean that recursion cannot be used in this example? Or it should be implemented differently?
Thanks,
Pit
recursion has it's place, of course, but it does not serve string manipulation very well.
without using a tally table, i'd do it like this: just a simple loop and string concatenation:
ALTER function CharReversal(@inputstring varchar(max))
returns varchar(max)
WITH SCHEMABINDING
AS
BEGIN
DECLARE @i int,
@Results varchar(max)
SET @Results=''
SET @i = 1
WHILE @i <= DATALENGTH(@inputstring)
BEGIN
SET @Results = SUBSTRING(@inputstring,@i,1) + @Results
SET @i=@i + 1
END
RETURN @Results
END
select dbo.CharReversal('abc123xyz')
--Results:zyx321cba
Lowell