I want to search a table's varchar column for content in another table's varchar column.
Certain words are banned and I want to identify the rows that have the banned words. I want an EXACT match on the banned word.
I'm using MS SQL Server 2016.
Table 1:
CREATE TABLE [dbo].[BlogComment](
[BlogCommentId] [int] IDENTITY(1,1) NOT NULL,
[BlogCommentContent] [varchar](max) NOT NULL,
CONSTRAINT [PK_BlogComment] PRIMARY KEY CLUSTERED
(
[BlogCommentId] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS =
ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
3 rows - and the data in BlogCommentContent:
There are many of us.
This is the man.
I hear you.
Table 2:
CREATE TABLE [dbo].[BannedWords](
[BannedWordsId] [int] IDENTITY(1,1) NOT NULL,
[Description] [varchar](250) NOT NULL
CONSTRAINT [PK_BannedWords] PRIMARY KEY CLUSTERED
(
[BannedWordsId] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS =
ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
3 rows - and the data in Description:
though
man
hear
My Sql:
SELECT BlogCommentContent
FROM dbo.BlogComment,
dbo.BannedWords
WHERE ( CHARINDEX( [Description], BlogCommentContent, 1 ) ) > 1
It's finding 'man', 'hear' and 'man' in the word 'many'. So it returns 3 rows.
I only WANT EXACT matches. So only return 2 rows.
How do I accomplish this?