0

I have the following statement

SELECT *
FROM   Delivery_Note this_
WHERE  mycol like '%[126]%'

I've noticed this also returns rows that contain [123]. What is the best way to find exact matching in a string.

edit I appreciate this is not an efficient query. There a few other reasons for this approach.

1 Answer 1

2

Brackets specify a range when used with LIKE. You can use the ESCAPE keyword.

WHERE mycol LIKE '%\[126\]%' ESCAPE '\';

Of course if you are trying to match an exact string, you don't need LIKE, or you can drop the % characters and LIKE will behave like = (this makes it flexible to pass in wildcards or exact matches to a parameter).

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.