charindex() 最后计算白色字符,len() 在 T-SQL 中没有 [英] charindex() counts white chars in the end, len() doesn't in T-SQL

查看:24
本文介绍了charindex() 最后计算白色字符,len() 在 T-SQL 中没有的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想找到最后一个/字符的索引,但问题是
LEFT(target, LEN(target) - CHARINDEX('/', REVERSE(target)))
不起作用,因为目标列中的字符串最后有很多空格字符,并且 charindex 函数包含空格,但 len 没有.

I want to find an index of the last / character, but the problem is that
LEFT(target, LEN(target) - CHARINDEX('/', REVERSE(target)))
doesn't work because the string in target column has a lot of space characters in the end and the charindex function includes the spaces, but len doesn't.

是否有其他函数可以替代其中之一?

Is there any other function to replace one of them?

推荐答案

RTRIM 函数修剪尾随空格.

LEFT(target,
     LEN(target) - CHARINDEX('/', REVERSE(RTRIM(target))))

这篇关于charindex() 最后计算白色字符,len() 在 T-SQL 中没有的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆