title: SQL Server XML Type Select Where Attribute = X From Any Tag
body: <pre><code>select *
  from tablename
  where CONVERT(xml, Sections).value('(/sections/section/@value)[1]', 'varchar(1)') = 'f'
  </code></pre>
  
  <p>will properly retrieve a record with the following value in the Sections column:</p>
  
  <pre><code>&lt;sections&gt;&lt;section value="f" priority="4" /&gt;&lt;section value="a" priority="4" /&gt;&lt;/sections&gt;
  </code></pre>
  
  <p>But misses this:</p>
  
  <pre><code>&lt;sections&gt;&lt;section value="w" priority="4" /&gt;&lt;section value="f" priority="4" /&gt;&lt;/sections&gt;
  </code></pre>
  
  <p>Obviously this is the problem "<code>/sections/section/@value)[1]</code>" but I don't understand the syntax and Google hasn't been too helpful.  I found some code that got me this far, but I don't know how to modify it so that it will look through all  tags instead of just the first one.  I tried dropping the <code>[1]</code> but that gave the following error:</p>
  
  <pre><code>XQuery [value()]: 'value()' requires a singleton (or empty sequence), found operand of type 'xdt:untypedAtomic *'
  </code></pre>