4

Using below query to filter records:

select * from SearchRecord where searchkeyword1  like  '[%'

Tried this also

select * from SearchRecord where searchkeyword1  like  '%[%'

Records in table contain these values (as per below i need last 2 records, why this simple like won't filter records)

"Affiliate" means
"Agent's Rate of Exchange" means
["Aggregate Total Commitments" means
["Agreed Security Principles" means
13

Your search pattern contains a wildcard character [, you should enclose it in brackets or use ESCAPE character like this:

declare @SearchRecord table (searchkeyword1 varchar(100));
insert into @SearchRecord values
('"Affiliate" means'),
('"Agent''''s Rate of Exchange" means'),
('["Aggregate Total Commitments" means'),
('["Agreed Security Principles" means');

select * 
from @SearchRecord 
where searchkeyword1  like  '![%' ESCAPE '!';

select * 
from @SearchRecord 
where searchkeyword1  like  '[[]%';

All this is described here: LIKE (Transact-SQL)

3

You can use ESCAPE '<some char>' to tell SQL how to interpret the character after .

SELECT * FROM SearchRecord WHERE SearchKeyword LIKE '%\[%' ESCAPE '\';

db<>fiddle here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.