开发者

How to reverse values in a string in T-SQL

开发者 https://www.devze.com 2023-01-19 15:35 出处:网络
Using T-SQL, I\'m trying to find the easiest way to make: \"abc.def开发者_StackOverflow.ghi/jkl\" become \"abc/def/ghi.jkl\"?

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

精彩评论

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