环球网校是美国纳斯达克上市企业欢聚时代(NASDAQ:YY)旗下品牌 | 住房和城乡建设部 建筑人才培训合作单位
您现在的位置在: > 计算机类 > 计算机等级考试 > 考试辅导 >

计算机等级考试辅导:sql2005中一个xml聚合的例子

2010-07-10 来源:互联网 作者:第一考试网

  --建立测试环境
  set nocount on
  create table test(ID varchar(20),NAME varchar(20))
  insert into test select ’1’,’aaa’
  insert into test select ’1’,’bbb’
  insert into test select ’1’,’ccc’
  insert into test select ’2’,’ddd’
  insert into test select ’2’,’eee’
  go
  --测试
  select *from (select distinct id from test)a
  OUTER APPLY(
  select value=’<root>’+(
  select name from test path
  where id = A.id
  for xml auto)+’<root/>’) b
  --删除测试环境
  drop table test
  set nocount off
  /*--结果
  id value
  --------------------
  1 <root><path name="aaa"/><path name="bbb"/><path name="ccc"/><root/> #
  2 <root><path name="ddd"/><path name="eee"/><root/>
  */

#

责编: 返回顶部  打印

关于我们联系我们友情链接网站声明网站地图广告服务帮助中心