从结尾查找字符索引

时间:2018-01-08 08:12:37

标签: sql sql-server

有人能告诉我如何从最后找到角色指数吗?

示例:

John(Jk)

我想从最后找到(

结果:

4

3 个答案:

答案 0 :(得分:1)

您可以使用CHARINDEX

语法:

CHARINDEX ( expressionToFind , expressionToSearch [ , start_location ] )   

最佳Regarads!

答案 1 :(得分:1)

重新定义问题的一种方法是,您希望从颠倒的字符串中找到{em>第一个出现的<link rel="stylesheet prefetch" href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.0.0-beta.2/css/bootstrap.css"> <link rel="stylesheet prefetch" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css"> <div class="container"> <div class="boxes"> <div class="row"> <div class="col-md-4 offset-md-2"> <div class="box d-flex flex-column justify-content-between"> <h4> <div>Lorem ipsum dolor sit amet consectetur adipisicing elit. Mollitia laudantium autem omnis saepe officia alias...</div> </h4> <i class="fa fa-long-arrow-right align-self-end"></i> </div> </div> <div class="col-md-4"> <div class="box d-flex flex-column justify-content-between"> <h4> Lorem ipsum dolor sit amet consectetur adipisicing elit. Mollitia laudantium laudantium autem autem omnis saepe officia alias... </h4> <i class="fa fa-long-arrow-right align-self-end"></i> </div> </div> </div> </div> </div>

(

Demo

在上面的演示中,字符串SELECT LEN(col) - CHARINDEX('(', REVERSE(col)) + 1 FROM yourTable; 中最终(的char索引正确地确定为5.

答案 2 :(得分:0)

使用charindex()reverse()函数从末尾查找索引

select charindex('(', reverse(data)) from table