<p>Say I've got this table (SQL Server 2005):</p>

<pre><code>Id =&gt; integer  
MyField =&gt; XML
</code></pre>

<p><b>Id  MyField</b>  </p>

<pre><code>1   &lt; Object&gt;&lt; Type&gt;AAA&lt; /Type&gt;&lt; Value&gt;10&lt; /Value&gt;&lt; /Object&gt;&lt; Object&gt;&lt; Type&gt;BBB&lt; /Type&gt;&lt;Value&gt;20&lt; /Value&gt;&lt; /Object&gt;  
2   &lt; Object&gt;&lt; Type&gt;AAA&lt; /Type&gt;&lt; Value&gt;15&lt; /Value&gt;&lt; /Object&gt;  
3   &lt; Object&gt;&lt; Type&gt;AAA&lt; /Type&gt;&lt; Value&gt;20&lt; /Value&gt;&lt; /Object&gt;&lt; Object&gt;&lt; Type&gt;BBB&lt; /Type&gt;&lt; Value&gt;30&lt; /Value&gt;&lt; /Object&gt;  
</code></pre>

<p>I need a TSQL query which would return something like this:</p>

<pre><code>Id  AAA     BBB  
1   10      20  
2   15      NULL  
3   20      30  
</code></pre>

<p>Note that I won't know if advance how many <code>'Type'</code> (eg AAA, BBB, CCC,DDD, etc.) there will be in the xml string.</p>

You will need to use the
XML querying in sql server
to do that.
somethings like
```
```
select id, MyField.query('/Object/Type[.="AAA"]/Value') as AAA, MyField.query('/Object/Type[.="BBB"]/Value) AS BBB
```
```
not sure if that's 100% correct xquery syntax, but it's going to be something like that.