Skip to content
Advertisement

Fetch data from XML – XMLGet function using with Attribute Name and its value in Snowflake

I have an xml which I need to read using Snowflake SQL. I need to use the attribute name and lits value to fetch the data. For example -> id and “bk101” to fetch the contents.

I am currently using below query-

In this case I am passing the index 0-4 to fetch the data is not producing correct results.

Instead of this I need to fetch the records using attribute name and its value(id=”bk101″)

Advertisement

Answer

This will get you the id and value for each book:

enter image description here

Then a pivot presents the results as desired:

enter image description here

Table setup:

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