考试辅导

名师推荐

试听名师的课 查看所有名师

计算机等级考试辅导:sql2005中一个xml聚合的例子 发布时间:2010-07-10 17:26 来源:互联网

  --建立测试环境
  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/>
  */

第一考试网友情提示:如果您遇到任何疑问,请登录第一考试网考试辅导频道或添加qq:,第一考试网以“为考友服务”为宗旨,秉承“快乐学习,轻松考试!”的理念,旨在为广大考友打造一个良好、温馨的学习与交流平台,欢迎持续关注。以上是小编为大家推荐的《计算机等级考试辅导:sql2005中一个xml聚合的例子》相关信息。

编辑推荐

计算机等级考试辅导:SQL中JOB的运行状态

计算机等级考试辅导:SQLSERVER2005的引用

三级:把数据导入不同的表空间

2009年三级信息管理技术辅导:战略数据规划

教你三种方法卸载Windows7SP1Beta