SQl查询像方括号 [英] SQl Query Like Square Bracket

查看:92
本文介绍了SQl查询像方括号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





我有下面的字符串我需要检查我的字符串是否包含方括号 ['。

Hi,

I have the string below i need to check whether the my string contains square bracket or not '['.

@SEARCH_STRING = TestData[Size]

IF (@SEARCH_STRING like '[[]' )
....



i在下面链接:搜索条件中的模式匹配 [ ^ ]

推荐答案

尝试:

Try:
...LIKE '%[[]%'...


请阅读我对这个问题的评论...



我最好的猜测是:

Please, read my comment to the question...

My best guess is:
DECLARE @SEARCH_STRING VARCHAR(255) = 'Whatever [!] the string is... It is for...'
DECLARE @counter INT = 0
DECLARE @stringlenght INT = LEN(@SEARCH_STRING)

WHILE (@counter<=@stringlenght)
BEGIN
    IF (SUBSTRING(@SEARCH_STRING, @counter,1)='[')
        SELECT CONCAT('A ''',  SUBSTRING(@SEARCH_STRING, @counter, 1), ''' has been found on ', CONVERT(VARCHAR(3), @counter), '. position.')
    SET @counter = @counter + 1
END





结果:



Result:

A '[' has been found on 10. position.


您好,





您只能使用[]查找指定范围内的任何单个字符(例如,[af])或set(例如,[abcdef])



这是您的要求的准确答案



Hi,


you can use [ ] only to find any single character within the specified range (for example, [a-f]) or set (for example, [abcdef])

this is exact answer for your requirement

DECLARE @SEARCH_STRING1 NVARCHAR(MAX) = 'I Love My [India]'

DECLARE @SEARCH_STRING2 NVARCHAR(MAX) = 'I Love My India'


IF(@SEARCH_STRING1 LIKE '%[%' )
BEGIN 
PRINT '@SEARCH_STRING1 has ['
END
ELSE 
BEGIN 
PRINT '@SEARCH_STRING1 not Contain ['
END


IF(@SEARCH_STRING2 LIKE '%[%' )
BEGIN 
PRINT '@@SEARCH_STRING2 has ['
END
ELSE 
BEGIN 
PRINT '@@SEARCH_STRING2 not Contain ['
END

这篇关于SQl查询像方括号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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