I'm pretty new to using XML with TSQL, and recently ran into an issue that I can't think around and need your help with.
Scenario:
I have a query built that returns quite a few columns, one of which contains a UNC path to an .xml file. For simplicity's sake, lets just say there's 2 columns: GUID, filePath
Example values:
GUID | filePath
0001 | \\server\folder\file1.xml
0002 | \\server\folder\file2.xml
0003 | \\server\folder\file3.xml
Goal: There are three field values in each xml file that I want returned (shown below) but there are additional fields over than just the three I want.
xml:
<form>
<field>
<name>TextboxAllocation3</name>
<value>0</value>
</field>
<field>
<name>TextboxAllocation1</name>
<value>0</value>
</field>
<field>
<name>TextboxAllocation2</name>
<value>0</value>
</field>
...
</form>
Question: How could I craft a query that would return:
GUID, TextboxAllocation1, TextboxAllocation2, TextboxAllocation3
, when every GUID has a different filepath?
What I've tried:
• Using openrowset, but specifying the target can't be a variable (or in this case, it can't be the filePath from the query), it must be text, which lead me down the path of dynamic SQL which quickly turned into an amalgamation of spaghetti that I'm realizing I can't think through right now.