在我的 sql 表中,我有一些数据如下,
ItamName
-----
Småsenter (Sandvika Småsenter)
Brilleland
Game
Name It
我写了如下查询,
SELECT
(Select I.ItamName from ItemMaster I where I.ItemId=A.ItemName and I.LanguageId='no'
and I.SiteId='sandvikas') as elementname,
sum(clicks) as click from Analytics A
where ItemType='Shop' and DateOfEvent >='2013-10-01' and DateOfEvent<='2013-10-31'
and SiteName='sandvikas'
group by ItemName order by click desc, ItemName Asc FOR XML RAW('Table'),ROOT('NewDataSet')
这给了我输出
<NewDataSet>
<Table elementname="Brilleland" click="2" />
<Table elementname="Name It" click="2" />
<Table elementname="Småsenter (Sandvika Småsenter)" click="1" />
<Table elementname="Game" click="1" />
</NewDataSet>
数据中也有一些特殊字符。我希望我的 xml 数据按字母顺序排列如下,
<NewDataSet>
<Table elementname="Brilleland" click="2" />
<Table elementname="Game" click="1" />
<Table elementname="Name It" click="2" />
<Table elementname="Småsenter (Sandvika Småsenter)" click="1" />
</NewDataSet>
问候桑吉塔