在 SQL 2008 中获取最后一个 indexof 字符的最佳方法是什么 [英] What is best way to get last indexof character in SQL 2008
本文介绍了在 SQL 2008 中获取最后一个 indexof 字符的最佳方法是什么的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在 C# 中,我们有 String.LastIndexOf
方法来获取给定字符串的特定字符位置的最后一个索引.在 SQL Server 中是否有类似的功能可以做同样的事情.我尝试使用 CHARINDEX
但无法实现.
In C#, we have String.LastIndexOf
method to get a last index of a particular character location for given string. Is there any similar function to do same in SQL Server. I tried using CHARINDEX
but couldn't able to achieve it.
推荐答案
有点棘手,但你可以这样做:
A little tricky, but you could do something like:
REVERSE(SUBSTRING(REVERSE([field]),0,CHARINDEX('[char]',REVERSE([field]))))
这篇关于在 SQL 2008 中获取最后一个 indexof 字符的最佳方法是什么的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文