开发者

JOIN using a 'LIKE' on an XML Node?

I've got a view that joins tables using a match on an xml node, like this example:

....CROSS APPLY xmlData.Nodes('/element/subElement')....

The problem is we now have elements called 'element2' and 'element3' which don't get picked up. Is there a way to include these, almost using a LIKE on the nodes to pick these up as well?

Something along these lines:

....CROSS APPLY xmlData.Nodes('/element%/subElement')....

or is it a case开发者_StackOverflow中文版 of adding these extra nodes into the view manually?

Thanks


You can use an XQuery expression

CROSS APPLY xmlData.nodes('/*/subElement')

Update

If you need to be more specific you can use

CROSS APPLY xmlData.nodes('/*[substring(local-name(),1,7)="element"]/subElement')

in theroy starts-with would be better than substring but it does not work in SQL-server-2005 and I can't test with SQL-server-2008

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜