Note that there are some explanatory texts on larger screens.

plurals
  1. POMS-SQL 2008 Whole Word Matches
    primarykey
    data
    text
    <p>I've spent a few hours researching this and am pretty stumped, probably due to my in-often use of RegEx expressions.</p> <p>I am looking to match a whole word in either a VARCHAR or TEXT type column in Microsoft SQL 2008.</p> <p>I have a CLR Assembly <a href="https://www.simple-talk.com/sql/t-sql-programming/clr-assembly-regex-functions-for-sql-server-by-example/" rel="nofollow">RegEx Function installed</a>.</p> <p>I need it to match gun in these sample cases:</p> <ul> <li><strong>Gun</strong> Loaded</li> <li>Loaded <strong>Gun</strong></li> <li>My <strong>Gun</strong> Is Loaded</li> </ul> <p>and NOT in these cases:</p> <ul> <li>Guns are great</li> <li>I have my guns</li> <li>My guns are great</li> </ul> <p>I would rather not go down the full text search route.</p> <p>Here's some things that I've tried but have failed:</p> <pre><code>WHERE PATINDEX( '%[^a-zA-Z_]' + @keyword + '[^a-zA-Z_]%', name) &gt; 0 </code></pre> <p>... doesn't take into account the word at the beginning of the string</p> <pre><code>WHERE name LIKE '%\b' + @keyword + '\b%' </code></pre> <p>... doesn't return anything</p> <pre><code>WHERE name LIKE '%[^A-Za-z]' + @keyword + '[^A-Za-z]%' </code></pre> <p>... doesn't take into account the word at the beginning of the string</p> <p>... along with some others I didn't save</p> <p>I can't seem to rely upon regular expression testers such as <a href="http://gskinner.com/RegExr/" rel="nofollow">http://gskinner.com/RegExr/</a> to get me through this. Any help appreciated.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload