title: SQL Server XQuery in one line?
body: <pre><code> DECLARE @myXml XML
  
   SET @myXml =  CONVERT(xml, '&lt;a key="2"&gt;&lt;/a&gt;', 1)
  
   SELECT  s.value('@key', 'VARCHAR(8000)')   AS myKey from   @myXml.nodes('/a')  t(s)
  </code></pre>
  
  <p>answer : </p>
  
  <p><img src="https://i.stack.imgur.com/d65eD.jpg" alt="enter image description here"></p>
  
  <p>which is fine.</p>
  
  <p>I want to do it without declaring the @<code>myXml</code> variable.</p>
  
  <p>Something like  : </p>
  
  <pre><code> SELECT  
      s.value('@key', 'VARCHAR(8000)') AS myKey 
   FROM 
      CONVERT(xml, N'&lt;a key="2"&gt;&lt;/a&gt;', 1) .nodes('/a')  t(s)
  </code></pre>
  
  <p>but I get an error : </p>
  
  <p><img src="https://i.stack.imgur.com/otTYa.jpg" alt="enter image description here"></p>