title: PATINDEX, wildcards and variables
body: <p>How do you get <code>PATINDEX</code> to to do a wildcard card match on a variable that includes a <code>%</code> character?</p>
  
  <p>In the following I want <code>PATINDEX</code> to return the starting position of '%3d':</p>
  
  <pre><code>DECLARE @inputText as VARCHAR(100)
  DECLARE @s as Int   
  DECLARE @cIn as CHAR(3)
  
  SET @inputText = 'OEi49j3DNxE%3d'
  SET @cIn = '%3d'
  SET @s = PATINDEX('%' + @cIn +'%', @InputText)
  </code></pre>
  
  <p>As you can see from the <code>@InputText</code>, this starts at position 12. </p>
  
  <blockquote>
    <p>OEi49j3DNxE <strong>%3d</strong></p>
  </blockquote>
  
  <p>However <code>PATINDEX</code> seems to return the start position at 7 because it seems to drop the <code>%</code> from <code>CIn</code>:</p>
  
  <blockquote>
    <p>OEi49j<strong>3D</strong>NxE%3d</p>
  </blockquote>
  
  <p>How do I get look for <code>%3d</code> as specified, rather than <code>3d</code>?</p>