This is a variation/combination of these two questions, but I think I've done as they described:
- Getting element's name in XPATH
- XQuery [value()]: 'value()' requires a singleton (or empty sequence), found operand of type 'xdt:untypedAtomic *'
Is there a way to get the name of a node in a SQL Server 2016 T-SQL query?
I want to do this:
select
trcid,
trcXML.value(
'local-name(//*[local-name()="after"][1]/*[1])',
'varchar(32)'
) as XmlTableName,
trcXml,
trcGUID,
trcCorrID
from trace
order by trcId desc
I have explicitly included the [1]
after each item in the hierarchy.
Error: XQuery [trace.trcXML.value()]: 'local-name()' requires a singleton (or empty sequence), found operand of type
'element(*,xdt:untyped) *'
Sample data:
<s1:DB2Request xmlns:s1="XYZDB2">
<s1:sync>
<s1:after identityInsert="false">
<s1:PG204AT5>
<s1:ISA06>1975111</s1:ISA06>
etc...
</s1:PG204AT5>
</s1:after>
</s1:sync>
</s1:DB2Request>
I want the table name (this is a BizTalk "update-gram") which is between the "after" and the ISA06 elements, in this case: PG204AT5.
Tested in xpathtester.com: local-name(//*[local-name()="after"][1]/* [1])
- for some reason when I save it the XPATH gets changed: http://www.xpathtester.com/xpath/2bd602d8fc7aee0484de14bf93f71ef2