title: How to get XML values into table with dynamic query? Column name or node name are not fix in XML
body: <pre><code>DECLARE  @XML1 XML =
  '&lt;sender id="1" operation="NewValue" LastName="XYZ" loginId="10029" /&gt;
  &lt;sender id="2" operation="OldValue" LastName="PQR" loginId="10029" /&gt;'
  
  SELECT T.C.value('local-name(.)', 'varchar(50)') AS NodeName,
      T.C.value('(.)[1]', 'varchar(50)') AS NodeValue
  FROM @xml1.nodes('//*') AS T(C)
  </code></pre>
  
  <h2>From OP's comment</h2>
  
  <p>One more example</p>
  
  <pre><code>DECLARE @xml XML = 
  '&lt;row&gt; 
   &lt;operation&gt;NewValue&lt;/operation&gt; 
   &lt;LastName&gt;Gandhi&lt;/LastName&gt; 
   &lt;loginId&gt;1011&lt;/loginId&gt; 
   &lt;/row&gt; 
   &lt;row&gt; 
   &lt;operation&gt;OldValue&lt;/operation&gt; 
   &lt;LastName&gt;Gandhi&lt;/LastName&gt; 
   &lt;loginId&gt;1010&lt;/loginId&gt; 
   &lt;/row&gt;' 
  
  SELECT T.C.value('local-name(.)', 'varchar(50)') AS NodeName, 
         T.C.value('(.)[1]', 'varchar(50)') AS NodeValue 
  FROM @xml.nodes('row/*') AS T(C) 
  WHERE T.C.value('(//row/operation/text())[1]', 'VARCHAR(20)') = 'NewValue'
  </code></pre>
  
  <p>(I want to get result like this query but my XML format is different).</p>