title: Xquery to get the value of a specific element from an XML which is stored as [XML Nullable column] in DB2
body: <p>Consider the following XML :</p>
  
  <pre><code>     &lt;Employee&gt;
          &lt;EmpDetails&gt;   
               &lt;Name&gt;huff&lt;/Name&gt;
          &lt;/EmpDetails&gt;
       &lt;/Employee&gt;
  </code></pre>
  
  <p>Above XMLis stored as a <code>column(DATA)</code> with data type <code>[XML NULLABLE]</code> in a table in DB2.
  Assume that the structure of the table is something like this:</p>
  
  <pre><code>      Table name:  REGEVENT
       Columns are: REFID (VARCHAR), APPID(VARCHAR), DATA(XML NULLABLE)
  </code></pre>
  
  <p>Suppose the value in the table is: <code>REFID(12345)</code>, <code>APPID(54321)</code>, DATA(Employee xml as mentioned above).</p>
  
  <p>Now I have to get the value of element  in the XML stored in column DATA using Xquery (Or any other way is also fine).</p>
  
  <p>I am trying the following query, but I am getting the value EmpName as NULL.</p>
  
  <pre><code>select XMLCAST(XMLQUERY('$d/Employee/EmpDetails/Name' PASSING rg.DATA AS "d") AS VARCHAR(50)) AS EmpName from REGEVENT  rg where REFID='12345';
  </code></pre>