如何在PATINDEX模式参数中转义下划线字符? [英] How to escape underscore character in PATINDEX pattern argument?

查看:183
本文介绍了如何在PATINDEX模式参数中转义下划线字符?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经找到一个解决方案来查找PATINDEX下划线的位置:

I've found a solution for finding the position of an underscore with PATINDEX :

DECLARE @a VARCHAR(10)  
SET     @a = '37_21'

PRINT PATINDEX('%_%', @a)                    -- return 1 (false)
PRINT PATINDEX('%!%', REPLACE(@a, '_', '!')) -- return 3 (correct)

有其他想法吗?像一种逃避下划线字符的方法?

Have you other ideas? Like a way to escape the underscore character?

推荐答案

我一直用括号做:'%[_]%' c $ c>

I've always done it with brackets: '%[_]%'

这篇关于如何在PATINDEX模式参数中转义下划线字符?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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