简体   繁体   English

如何在T-SQL中反转字符串中的值

[英]How to reverse values in a string in T-SQL

Using T-SQL, I'm trying to find the easiest way to make: 使用T-SQL,我试图找到最简单的方法:

"abc.def.ghi/jkl" become "abc/def/ghi.jkl"? “abc.def.ghi / jkl”成为“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 链接文字

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM