title: SQL Server Like Match and Exclude
body: <p>I have a table (DataTable) with a column that contains data like this in one of the columns:</p>
  
  <pre><code>DataColumn    
  ABCD
  ABCE
  ABCF
  ABXY
  </code></pre>
  
  <p>I have another table (MatchTable) that includes a pattern column and value column that can be used to get matching rows from the DataTable based on the match:</p>
  
  <pre><code>MatchPattern   Value
  AB%            1
  </code></pre>
  
  <p>I want to exclude the ABCE row from the result set and I don't want to have rows in my match table for ABCD%, ABCF%, etc as the ABCE is the exception to the rule.  My pattern could be AB[^C]%, but that will exclude all ABCs and I only want to exclude ABCE.  The sql for this is:</p>
  
  <pre><code>SELECT D.DataColumn, P.Value
  FROM MatchTable M
  INNER JOIN DataTable D ON D.DataColumn LIKE M.Pattern
  </code></pre>
  
  <p>I know I could add another column to my matching table called something like ExcludePattern with the following:</p>
  
  <pre><code>MatchPattern   ExcludePattern Value
  AB%            ABCE           1
  
  SELECT D.DataColumn, P.Value
  FROM MatchTable M
  INNER JOIN DataTable D ON D.DataColumn LIKE M.MatchPattern
                            AND D.DataColumn NOT LIKE M.ExcludePattern
  </code></pre>
  
  <p>I am wondering if there is a way to create a like pattern that will match all ABs except for ABCE in one pattern?  Basically, can this be done using the built-in like or do I have to implement regex?</p>