Skip to content
Advertisement

XML to SQL – Selecting multiple nodes with the same name

I have working code that can select a few values from an XML file. The problem is that I have multiple nodes with the same name.

Here is a snippet of the XML:

My SQL is the following:

Where I can’t get what I need is the [Component 2]. I want to basically select ALL of the “Address_Component_Type_ID” in the file, but they are all named the same and under other nodes that are named the same. How can I specify in my SQL to grab all of the Component Types? Thank you for looking!

Advertisement

Answer

Depends what you want to do… If you know there are exactly 2 “Address_Components” that you want to grab, you can modify your query like so:

And the results look like this:

However, if there can be any number of “Address_Components”, and you want to grab them into separate records, you can rewrite your query like this:

And the results look like this:

User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement