15,042,397 members
See more:
Hi,

I have the string below i need to check whether the my string contains square bracket or not '['.
SQL
@SEARCH_STRING = TestData[Size]

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

i referred below link: Pattern Matching in Search Conditions[^]
Posted
Updated 25-May-15 22:10pm
v2
Maciej Los 26-May-15 4:12am

Based on this small piece of code we can't even guess what are you trying to achieve... Please, be more specific and provide more details.

## Solution 1

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

## Solution 2

My best guess is:
SQL
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.
v2

## Solution 3

Hi,

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

SQL
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
jaket-cp 27-May-15 4:17am

This is what is printed when your solution is run:
@SEARCH_STRING1 not Contain [
@@SEARCH_STRING2 not Contain [

Clearly not the result you expected.
Look at solution 1 and read the link in question 'Pattern Matching in Search Conditions', section 'Searching for Wildcard Characters'