title: Parsing XML with XMLNS in SQL Server 2008 R2
body: <p>I'm fairly new to querying XML datatypes. We receive XMLs from partners and one such partner sends us XMLs like this:</p>
  
  <pre><code>DECLARE @ResultData XML = '&lt;outGoing xmlns="urn:testsystems-com:HH.2015.Services.Telephony.OutGoing"&gt;
      &lt;customer&gt;
          &lt;ID&gt;158&lt;/ID&gt;
      &lt;/customer&gt;
  &lt;/outGoing&gt;'
  </code></pre>
  
  <p>In this example, I would like to pull only the ID out of the XML, but it seems the xmlns is preventing me from getting anything inside the XML:</p>
  
  <pre><code>SELECT cust.value('(ID)[1]', 'VARCHAR(40)') as 'CustomerID'
  FROM    @ResultData.nodes('/outGoing/customer') as t(cust)
  </code></pre>
  
  <p>returns NUll, but if I <em>manually</em> remove the XMLNS from the XML I get 158.</p>
  
  <p>I've experimented with <code>WITH XMLNAMESPACES</code> to see if I could use that, but I'm obviously missing something.  Since these XMLs will be coming in automatically, I would like to be able to parse the XML, but right now I'm stuck.  </p>