是否可以查询 XML 以查找特定元素是否具有特定值?例如,如果我想查看下面的 XML 在<ContactFName>.
但请注意,元素的位置可能会改变。在某些情况下,它可能在/root/MCTLocations/MCTLocation,或者可能跳到根下,或者出现在其他地方......
并且,是否可以参数化元素名称?
DECLARE @table TABLE (XmlCol XML)
INSERT INTO @table (XmlCol) VALUES ('
<root>
<MCTClientName>John</MCTClientName>
<MCTClientCity>Palm Beach</MCTClientCity>
<MCTLocations>
<MCTLocation>
<Address>1234 Main Street</Address>
<ContactFName>Chris</ContactFName>
<ContactLName>Brandt</ContactLName>
</MCTLocation>
</MCTLocations>
</root>')
SELECT * FROM @table WHERE ??
Run Code Online (Sandbox Code Playgroud)