title: SQL Server Xml query with undeclared prefix
body: <p>I have a variable in SQL Server 2008 that contains a part of a XML column and I am having trouble querying it. The XML <em>can</em> contain a prefix "ns0" or not. I want to retrieve [from] from the xml. The query I tried was this:</p>
  
  <pre><code>DECLARE @Params XML
  SET @Params = '&lt;filter&gt;
                        &lt;ns0:from&gt;2016-09-19&lt;/ns0:from&gt;
                        &lt;ns0:to&gt;2017-01-01&lt;ns0:to&gt;
                 &lt;/filter&gt;';
  SELECT @Params.value('(/*:filter/*:from)[1]', 'Varchar(max)') AS [from]
  </code></pre>
  
  <p>I don't have a XML header to declare any namespace. When I try to execute this, I got this error:</p>
  
  <pre><code> XML parsing: line 1, character 10, undeclared prefix
  </code></pre>
  
  <p>But when I try this, everything works fine:</p>
  
  <pre><code>SET @Params = '&lt;filter&gt;
                      &lt;from&gt;2016-09-19&lt;from&gt;
                      &lt;to&gt;2017-01-01&lt;to&gt;
                 &lt;/filter&gt;
  SELECT @Params.value('(/*:filter/*:from)[1]', 'Varchar(max)') AS [from]
  </code></pre>
  
  <p>How can I retrieve [from] using an XPath query given the above xml example with a prefix or without prefix?</p>