Skip to content

Instantly share code, notes, and snippets.

@javierguerrero
Created June 6, 2012 18:25
Show Gist options
  • Save javierguerrero/2883732 to your computer and use it in GitHub Desktop.
Save javierguerrero/2883732 to your computer and use it in GitHub Desktop.
SQL Exact Match
DECLARE @Tab TABLE(
[id] int,
[test] varchar(100))
INSERT INTO @Tab
VALUES (1, 'This is a test searching for like.')
INSERT INTO @Tab
VALUES (2, 'This is a test for alike messages.')
INSERT INTO @Tab
VALUES (3, 'It is likely the effort will fail.')
INSERT INTO @Tab
VALUES (4, 'I like rainy days.')
INSERT INTO @Tab
VALUES (5, 'like')
INSERT INTO @Tab
VALUES (6, 'I like')
INSERT INTO @Tab
VALUES (7, 'like hi.')
SELECT *
FROM @Tab
WHERE
test LIKE '%[^a-z]like[^a-z]%' OR
test LIKE 'like[^a-z]%' OR
test LIKE '%[^a-z]like' OR
test = 'like'
/*
The [^a-z] says that the characters before and
after must not be letters a-z. I hope this solves it for you!
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment