嗨,我在 SQL 表中有以下字符串Cities
:
Info
AUS / Melbourne (AUS) 16th Jul
AUS / Sydney (AUS) 16th Jul
USA/ New York (USA) 16th Jul
我希望提取并创建一个新列,所以我想要的结果是:
Info City
AUS / Melbourne (AUS) 16th Jul Melbourne (AUS)
AUS / Sydney (AUS) 16th Jul Sydney (AUS)
USA / New York (USA) 16th Jul New York (AUS)
我尝试过类似的事情:
Select
[Info],
SUBSTRING([Info],CHARINDEX('/ ',[Info])+2,10) as City
from Cities
但那是 10 个字符的固定宽度,而是我想要从/
括号到括号的字符串)
任何帮助将非常感激!
非常感谢
与其使用固定长度,为什么charindex
不像您所做的那样使用固定长度,而是使用两个分隔符?
select Substring([info], CharIndex('/',[info])+2, IsNull(NullIf(CharIndex(')',[info]),0)-CharIndex('/',[info])-1,Len([info])))
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句