I have an XML field that I know will have at least one \"ChildNode\" in it, but possibly more. I am trying to make a loop in T-SQL that will get the XML of each ChildNode a
There still could be a need to query sub elements which the answer to this question would not solve. You can just use sql:variable to satisfy nodes() requirement of a string literal argument to query sub elements of a specific node iteratively.
DECLARE @iterator = 1
SELECT
Child.value('(SomeElement)[1]', 'int'),
Child.value('(SomeOtherElement)[1]', 'Varchar(50)'),
FROM
XMLField.nodes("/RootNode/ParentNode[sql:variable("@iterator")]/ChildNode") AS N(Child)