【问题标题】:How to get a specific string from string in SQL Server?如何从 SQL Server 中的字符串中获取特定字符串?
【发布时间】:2015-07-24 12:14:01
【问题描述】:

这是我的字符串 'ABCDEF-24-04-07-001',我想要的只是将最后一个字符串用 -(连字符)分隔,即 001。

但对我来说另一个复杂性是,上面的字符串可能会有所不同,即它可能是“ABC-24-07-01”或“ABCDE-24-07-010”或“ABCDE-24-07-1”。

请帮我解决上述问题

【问题讨论】:

  • 到目前为止你尝试了什么?

标签: sql-server-2008 str-replace string-split substring


【解决方案1】:

这里是代码

DECLARE @string VARCHAR(32) = 'ABCDE-24-07-010';
select REVERSE(SUBSTRING(REVERSE(@string),0,CHARINDEX('-',REVERSE(@string))))

【讨论】:

    猜你喜欢
    • 2017-07-28
    • 2013-11-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-10-06
    相关资源
    最近更新 更多