title: Get values from XML using XQuery
body: <p>I am new in T-SQL and XQuery.</p>
  
  <p>I have XML column in DB with structure like this</p>
  
  <pre><code>     &lt;GPC xmlns:x="http://www.w3.org/2001/XMLSchema" xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns="..."&gt;
    &lt;GP&gt;
      &lt;N&gt;Amount1&lt;/N&gt;
      &lt;V i:type="X_AMT"&gt;
        &lt;AMT&gt;100001&lt;/AMT&gt;
        &lt;X_CODE&gt;Dollar&lt;/X_CODE&gt;
      &lt;/V&gt;
    &lt;/GP&gt;
    &lt;GP&gt;
      &lt;N&gt;Amount2&lt;/N&gt;
      &lt;V i:type="X_AMT"&gt;
        &lt;AMT&gt;0&lt;/AMT&gt;
        &lt;X_CODE /&gt;
      &lt;/V&gt;
    &lt;/GP&gt;
    &lt;GP&gt;
      &lt;N&gt;Amount3&lt;/N&gt;
      &lt;V i:type="X_AMT"&gt;
        &lt;AMT&gt;100001&lt;/AMT&gt;
        &lt;X_CODE&gt;Dollar&lt;/X_CODE&gt;
      &lt;/V&gt;
    &lt;/GP&gt;
    &lt;GP&gt;
      &lt;N&gt;Amount4&lt;/N&gt;
      &lt;V i:type="X_AMT"&gt;
        &lt;AMT&gt;0&lt;/AMT&gt;
        &lt;X_CODE /&gt;
      &lt;/V&gt;
    &lt;/GP&gt;
    &lt;GP&gt;
      &lt;N&gt;Amount5&lt;/N&gt;
      &lt;V i:type="X_AMT"&gt;
        &lt;AMT&gt;100001&lt;/AMT&gt;
        &lt;X_CODE&gt;Dollar&lt;/X_CODE&gt;
      &lt;/V&gt;
    &lt;/GP&gt;
    &lt;GP&gt;
      **&lt;N&gt;NeededAmount&lt;/N&gt;**
      &lt;V i:type="Y"&gt;
        &lt;DETAILS&gt;
          &lt;REFERENCE&gt;
            &lt;N&gt;**ReferenceName1**&lt;/N&gt;
            &lt;OId&gt;111111&lt;/OId&gt;
          &lt;/REFERENCE&gt;
        &lt;/DETAILS&gt;
        &lt;DETAILS&gt;
          &lt;REFERENCE&gt;
            &lt;N&gt;**ReferenceName2**&lt;/N&gt;
            &lt;OId&gt;22222&lt;/OId&gt;
          &lt;/REFERENCE&gt;
        &lt;/DETAILS&gt;
      &lt;/V&gt;
    &lt;/GP&gt;
  
    ...
  
    &lt;/GPC&gt;
  </code></pre>
  
  <p>This is query in SQL Server that i am using. The Query returns only one name - Name1.
  But there is two names, and there can be a 100 names, and i want to get that names.</p>
  
  <pre><code> SELECT v.Content.query(N'declare default element namespace "..."; 
      for $i in (GPC/GP) where ($i/N[1] eq "NeededAmount") return ($i)').value('declare default element namespace "..."; 
      (GP/V/DETAILS/REFERENCE/N)[1]', 'nvarchar(max)') AS NeededName
      FROM DB1.protected.WorkItem as v
      where v.Id = 1111
  </code></pre>
  
  <p>My qustion is: How can i modify this to get all names in document? Can someone help me?</p>
  
  <p>Thanks in advance.</p>