How to reverse values in a string in T-SQL
Using T-SQL, I'm trying to find the easiest way to make:
"abc.def开发者_StackOverflow.ghi/jkl" become "abc/def/ghi.jkl"?
Basically switch the . and /
Thank you
One way
select replace(replace(replace('abc.def.ghi/jkl','/','-'),'.','/'),'-','.')
you need to use an intermediate step, I chose the - symbol, choose something which won't exist in your string
SELECT REVERSE(@myvar) AS Reversed,
RIGHT(@myVar, CHARINDEX(‘ ‘, REVERSE(@myvar))) as Lastname;
took the answer from this guys blog. The first google result. You will need to modify it for your needs
link text
精彩评论