0
比方說,我在SQL Server中有一個表,其中包含帶內連接的查詢結果。如何在SQL Server上使用XQuery按屬性值對元素進行分組?
下面的XQuery:
select @code.query
(
'for $s in /root/row
return
<Foo Language="{data($s/@lang)}" Method="{data($s/@method)}" Returns="{data($s/@returnType)}">
<Bar ReferencedBy="{data($s/@callers)}" Static="{data($s/@static)}" />
</Foo>'
)
而其結果是:
<Foo Language="C#" Method="getFoos" Returns="FooCollection">
<Bar ReferencedBy="Baz" Static="true" />
</Foo>
<Foo Language="C#" Method="getFoos" Returns="FooCollection">
<Bar ReferencedBy="Bar" Static="false" />
</Foo>
我想其實是這樣的:
<Foo Language="C#" Method="getFoos" Returns="FooCollection">
<Bar ReferencedBy="Baz" Static="true" />
<Bar ReferencedBy="Bar" Static="false" />
</Foo>
什麼是做到這一點的最好辦法使用XQuery以避免使用LINQ和哈希表?
看起來您需要在FOO標記內部使用for循環來迭代要填充的BAR值。 – 2010-01-28 22:01:33