title: XQuery [value()]: 'value()' requires a singleton (or empty sequence), found operand of type 'xdt:untypedAtomic *'
body: <p>I'm trying to insert rows into a table using a select from XML. I think I'm close. Where am I going wrong?</p>
  
  <pre><code>declare @xmldata xml;
  set @xmldata = '&lt;Database&gt;
                    &lt;PurchaseDetails&gt;
                      &lt;PurchaseDetail&gt;
                        &lt;Upc&gt;72594206916&lt;/Upc&gt;
                        &lt;Quantity&gt;77&lt;/Quantity&gt;
                        &lt;PurchaseDate&gt;9/2010&lt;/PurchaseDate&gt;
                        &lt;PurchaseCity&gt;Dallas&lt;/PurchaseCity&gt;
                        &lt;PurchaseState&gt;TX&lt;/PurchaseState&gt;
                      &lt;/PurchaseDetail&gt;
                      &lt;PurchaseDetail&gt;
                        &lt;Upc&gt;72594221854&lt;/Upc&gt;
                        &lt;Quantity&gt;33&lt;/Quantity&gt;
                        &lt;PurchaseDate&gt;12/2013&lt;/PurchaseDate&gt;
                        &lt;PurchaseCity&gt;Nashville&lt;/PurchaseCity&gt;
                        &lt;PurchaseState&gt;TN&lt;/PurchaseState&gt;
                      &lt;/PurchaseDetail&gt;
                    &lt;/PurchaseDetails&gt;
                  &lt;/Database&gt;'
  
  insert into PurchaseDetails
  (Upc, Quantity, PurchaseDate, PurchaseCity, PurchaseState)
  select
      x.Rec.value('Upc','char(11)'),
      x.Rec.value('Quantity','int'),
      x.Rec.value('PurchaseDate','varchar(7)'),
      x.Rec.value('PurchaseCity','varchar(50)'),
      x.Rec.value('PurchaseState','char(2)')
  from @xmlData.nodes('//Database/PurchaseDetails/PurchaseDetail') as x(Rec)
  </code></pre>