SQL query to search in a sting for a specific value
<p>I made a C# program that stores questions and answers in a SQL database. To be more accessible I've added the option to search in a column called <code>Tags</code> that have up to 5 words split by comma. I tried the following code but it checks only the first value of the <code>Tags</code>:</p>

<pre><code>SELECT
    Id, Observations, Problem, Solution, Tags
FROM            
    IT
WHERE        
    (RTRIM(LTRIM(SUBSTRING(Tags, 1, CHARINDEX(',', Tags, 0) - 1))) IN (@a, @b, @c, @d, @e)) OR
    (RTRIM(LTRIM(SUBSTRING(Tags, CHARINDEX(',', Tags,0), CHARINDEX(',', Tags, CHARINDEX(',', Tags,0)) - 1))) IN (@a, @b, @c, @d, @e)) OR
    (RTRIM(LTRIM(SUBSTRING(Tags, CHARINDEX(',', Tags, CHARINDEX(',', Tags,0)), CHARINDEX(',', Tags, CHARINDEX(',', Tags, CHARINDEX(',', Tags,0))) - 1))) IN (@a, @b, @c, @d, @e)) OR
    (RTRIM(LTRIM(SUBSTRING(Tags, CHARINDEX(',', Tags, CHARINDEX(',', Tags, CHARINDEX(',', Tags,0))), CHARINDEX(',', Tags, CHARINDEX(',', Tags, CHARINDEX(',', Tags, CHARINDEX(',', Tags,CHARINDEX(',',Tags,0))))) - 1))) IN (@a, @b, @c, @d, @e)) OR
    (RTRIM(LTRIM(SUBSTRING(Tags, CHARINDEX(',', Tags, CHARINDEX(',', Tags, CHARINDEX(',', Tags, CHARINDEX(',', Tags,CHARINDEX(',',Tags,0))))), CHARINDEX(',', Tags, CHARINDEX(',', Tags, CHARINDEX(',', Tags, CHARINDEX(',', Tags, CHARINDEX(',', Tags,CHARINDEX(',',Tags,CHARINDEX(',',Tags,0))))))) - 1))) IN (@a, @b, @c, @d, @e))
</code></pre>

<p>I'd appreciate if your answer contains an explaining. Thanks!</p>