title: Need to use SQL variable to define namespace for XML.Value selection
body: <p>I know how to select a value from an XML field using xpath and defining namespaces, but I need to use several xpath queries and assign them to my selection. Is there an easier way than doing the following:</p>
  
  <pre><code>SELECT 
      id, name,
      [XML].value('declare namespace test="http://www.test.org/xml/";
                   declare namespace test2="http://www.test2.org";
                   (//test:Address[1][test2:Global=1]/test:Street)[1] ', 'varchar(max)') AS streetLocation1,
      [XML].value('declare namespace test="http://www.test.org/xml/";
                   declare namespace test2="http://www.test2.org";
                   (//test:Address[2][test2:Global=1]/test:Street)[1] ', 'varchar(max)') AS streetLocation2 
  FROM  
      TEST
  </code></pre>
  
  <p>I want to replace</p>
  
  <pre><code>'declare namespace test="http://www.test.org/xml/";
   declare namespace test2="http://www.test2.org";'
  </code></pre>
  
  <p>by using a variable. I tried to append strings but I got the following:</p>
  
  <blockquote>
    <p>The argument 1 of the XML data type method "value" must be a string literal.</p>
  </blockquote>
  
  <p>There has to be an easier way.</p>
  
  <p>Thanks,</p>
  
  <p>-James</p>