开发者

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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜