By using db<>fiddle, you agree to license everything you submit by Creative Commons CC0.
create table TableA(
ID int,
Description varchar(100),
Value int);
insert into TableA values
(1,'This is an example',11),
(2,'This is another example',3),
(3,'However this will be left out',5),
(4,'This isx nonfooxyz',100),
(5,'Fooxy is valid',10),
(6,'Foo isalso ok',20);
6 rows affected
create table TermsTable (Terms varchar(100));
insert into TermsTable values
('example'),
('foo'), ('is'),
('another');
4 rows affected
SELECT * FROM TableA;
ID | Description | Value |
---|---|---|
1 | This is an example | 11 |
2 | This is another example | 3 |
3 | However this will be left out | 5 |
4 | This isx nonfooxyz | 100 |
5 | Fooxy is valid | 10 |
6 | Foo isalso ok | 20 |
SELECT * FROM TermsTable;
Terms |
---|
example |
foo |
is |
another |
SELECT a.Description, a.Value
FROM TableA a
WHERE EXISTS (
SELECT 1
FROM TermsTable
WHERE '.' + a.description + '.' LIKE '%[^a-z]' + Terms + '[^a-z]%');
Description | Value |
---|---|
This is an example | 11 |
This is another example | 3 |
Fooxy is valid | 10 |
Foo isalso ok | 20 |
SELECT a.Description, a.Value
FROM TableA a
WHERE EXISTS (
SELECT 1
FROM TermsTable
WHERE a.description LIKE '%[^a-z]' + Terms + '[^a-z]%');
Description | Value |
---|---|
This is an example | 11 |
This is another example | 3 |
Fooxy is valid | 10 |
SELECT a.Description, a.Value
FROM TableA a
WHERE EXISTS (
SELECT 1
FROM TermsTable
WHERE CHARINDEX(Terms, a.description) > 0);
Description | Value |
---|---|
This is an example | 11 |
This is another example | 3 |
However this will be left out | 5 |
This isx nonfooxyz | 100 |
Fooxy is valid | 10 |
Foo isalso ok | 20 |