DECLARE @temp TABLE ( Location NVARCHAR(50) )
INSERT @temp (Location )
VALUES ('US/New York/A')
, ('New York/B')
, ('Japan/Tokyo/A')
, ('Tokyo/B')
, ('UK/London/A')
, ('London/B')
Select *
From @temp
Where Location Like '%/A'
There is no need to escape the /
in this case. You can simply use an expression with a trailing wildcard.
Edit based on change to OP
It appears you may have a misconception about how the []
pattern is interpreted in the LIKE function. When you have a pattern like '[US/New York]%'
, it is saying "Find values that start with any of the following characters U
,S
,/
,N
,e
,w
, (space), Y
, o
,r
, or k
. Thus, such a pattern would find a value South Africa
or Outer Mongolia
. It isn't looking for rows where the entire value is equal to US/New York
.
One way to achieve what you seek is it to use multiple Or
statements:
Select *
From @temp
Where Location Like 'US/New York%'
Or Location Like 'Japan/Tokyo%'
Or Location Like 'UK/London%'