You can check and try this query.
declare @X xml = '<row><A>1</A><B>xyz</B></row><row><A>2</A><B>jkl</B></row>';
select x.r.value('(A)[1]', 'varchar(100)') as [A],
x.r.value('(B)[1]', 'varchar(500)') as [B]
from @X.nodes('/row') as x(r);
Here is the output:
A B
-------
1 xyz
2 jkl
You can find the demo here.
To access the node name and their values dynamically you can try the following query.
DECLARE @input XML = '<row><A>1</A><B>xyz</B></row><row><A>2</A><B>jkl</B></row>'
SELECT
NodeName = C.value('local-name(.)', 'varchar(50)'),
NodeValue = C.value('(.)[1]', 'varchar(50)')
FROM @input.nodes('/row/*') AS T(C)
It will give output as shown below. To know more you can refer this SO answer.
NodeName NodeValue
--------------------
A 1
B xyz
A 2
B jkl
.nodes,.query,.value) to get any part of the XML you please, but not in the form of dynamic columns (either in name or in type), whileOPENXMLwants a schema or else it returns a generic table. If you know your data looks exactly like this, you can write a query to turn it into a rowset. Otherwise, you either need to get ugly with dynamic SQL or just leave it to the client.MyTable" and expecting SQL Server to know that you want toSELECTall columns from it, along with any related rows which can be found by a foreign key. You need to tell SQL Server how you expect to see the results.