反向子字符串
我正在尝试从字符串中提取一些字符。 例如,在(316409953_ND_0214202_000001.pdf)中,我需要在最后一个下划线_和“”之前的字符。 答案:000001 @test = 316409953_ND_0214202_000001.pdf
我尝试过:
REVERSE(SUBSTRING(REVERSE(test),CHARINDEX('.',REVERSE(test))+1,CHARINDEX('_',REVERSE(test)+1)))
我需要在子字符串的最后一部分时提供帮助。我遇到的第一个错误是“转换varchar值'fdp.100000_22024120_dn_359904613'转换时转换失败。” 其次,我只需要在最后一个“ _”之后选择它 请指导或让我知道是否有另一种方法可以做到这一点。
I am trying to extract some characters from a string.
For Example in (316409953_ND_02142022_000001.pdf) I need the characters after the last underscore _ and before the "."
Answer: 000001
@test = 316409953_ND_02142022_000001.pdf
I have tried:
REVERSE(SUBSTRING(REVERSE(test),CHARINDEX('.',REVERSE(test))+1,CHARINDEX('_',REVERSE(test)+1)))
I need help with the last part of substring. First error I am getting is "Conversion failed when converting the varchar value 'fdp.100000_22024120_DN_359904613' to data type int."
Secondly I need it to pick only after the last "_"
Please guide or let me know if there's another way to do this.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
此看起来喜欢SQL Server。
在这个假设和使用单个示例值的假设上,您可以尝试follolwing:
This looks like SQL Server.
On that assumption, and using the single example value, you can try the follolwing:
它不是很漂亮,但它可以完成工作; P
it isn't pretty but it does the job ;P