In a table in my data base I have a column in which the entire entry is a long XML String with the following structure:
<Group1>
<Title>
<Name>John Doe</Name>
<Phone>555-3421</Phone>
<Email>catman@gmail.com</Email>
(+more)
</Title>
</Group1>
This is my SELECT Statement and here is what it outputs:
SELECT TheKey, TheData FROM MyTable;
Output in SQL Server Management Studio:
TheKey TheData
10000 <Group1><Title><Name>John Doe</Name><Phone>893-3421</Phone><Email>catman@gmail.com</Email></Title></Group1>
10001 <Group1><Title><Name>Mary Sue</Name><Phone>381-2342</Phone><Email>thebestdude@gmail.com</Email></Title></Group1>
10002 <Group1><Title><Name>Mark Dark</Name><Phone>312-7626</Phone><Email>mybook231@gmail.com</Email></Title></Group1>
10003 <Group1><Title><Name>Garth Dan</Name><Phone>341-4572</Phone><Email>lampshade032@gmail.com</Email><State>California</State></Title></Group1>
I would like to write some sort of MS SQL query that will return the data like this to me:
TheKey Name Phone Email State
10000 John Doe 893-3421 catman@gmail.com NULL
10001 Mary Sue 381-2342 thebestdude@gmail.com NULL
10002 Mark Dark 312-7626 mybook231@gmail.com NULL
10003 Garth Dan 341-4572 lampshade032@gmail.com California
Notice how the last entry had an extra XML tag <State>
which the other entries did not. I would like it to be flexible like this - using some sort of parent/child references?
Any help doing this would be greatly appreciated, I just can't seem to find anything like it anywhere =)