I need to fetch ‘Apple’from the Description column of a table where user search ‘The apple not the’.
I have written something like this
set @ExactKey = N'The Apple'
set @NotKey =N'the'
SELECT R.ResourceId
FROM Resource R
WHERE Description LIKE @ExactKey OR ExternalIdentifier LIKE @ExactKey
AND ExternalIdentifier NOT LIKE @NotKey OR Description NOT LIKE @NotKey
This is not working
You’d need to force a binary or case sensitive collation for the LIKE and use leading and trailing
%wildcards (Edit: as noted by ck).I’m also guessing your ANDs/ORs are wrong too because of:
Something like
You’d be better with full text search though. What about the words “theory” or “tithe”?