次の形式のデータがあります。
user Id Value
-------------------------------
a 50000 5
a 50000 6
a 50000 7
b 50001 8
b 50001 9
b 50001 10
次の形式でフォーマットされた XML を取得したい
<RootNode>
<User "a">
<UserAttribute Id="50000" value="5"/>
<UserAttribute Id="50000" value="6"/>
<UserAttribute Id="50000" value="7"/>
</User>
<User "b">
<UserAttribute Id="50001" value="8"/>
<UserAttribute Id="50001" value="9"/>
<UserAttribute Id="50001" value="10"/>
</User>
</RootNode>
次の選択クエリを試しました:
select
[user] as '@user',
[id] as 'UserAttribute/@id',
[value] as 'UserAttribute/@value'
from
dbo.test
for xml path('User')
しかし、必要な出力が得られません。誰かが私に何が欠けているか教えてもらえますか?
現在の出力:
<User user="a">
<UserAttribute id="50000" value="5" />
</User>
<User user="a">
<UserAttribute id="50000" value="6" />
</User>
<User user="a">
<UserAttribute id="50000" value="7" />
</User>
<User user="b">
<UserAttribute id="50001" value="8" />
</User>
<User user="b">
<UserAttribute id="50001" value="8" />
</User>
<User user="b">
<UserAttribute id="50001" value="8" />
</User>