Question : reverse string using SQL function

Hi,

I want the function that reverse my string...
Example:
/12/13/14/
that should return
 /14/13/12/

i have to just pass the string

Answer : reverse string using SQL function

In the code attached you've got your function. Once you've created it you call it like that

select dbo.ReverseNumbers('/12/13/14/')
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:


create function ReverseNumbers (@str varchar(max))
returns varchar(max)
as
begin
	declare @output varchar(max)
	set @output = ''

	declare @i int

	set @i = charindex('/',@str)
	while @i>0 
	begin
		set @output = '/'+left(@str,@i-1) + @output
		set @str = stuff(@str,1,@i,'')
		set @i = charindex('/',@str)
	end
	set @output = @str + @output

	return @output
end
go
Random Solutions  
 
programming4us programming4us