积极答复者
sql for xml 重复节点的问题

问题
-
各位老师:
之前问过一个关于sql server生成 xml 的问题,谢谢邹建老师。
目前还碰到另外一个问题,就是在sqlserver中,我们可以将查询的不同两列起同一个名字,比如说
select col1 as 'col',col2 as 'col' from table,这样不会有任何问题,会出现两列列名是col的值
但是如果,将这个结果转换成xml 形式,那么由于这两个名字相同,会将结果归并,也就是说
select col1 as 'col',col2 as 'col' from table for xml path('item'),type
所产生的结果是 <item><col>col1_value col2_value</col><item>
这样的形式,目前我所需要的是
<item><col>col1_value</col><col> col2_value</col><item>
这样的形式,也就是说col1和col2列要在xml中分别输出同名的元素col,不要求合并
不知是否说的有些乱?
谢谢各位老师
- 已编辑 songqs 2011年5月3日 12:02
答案
-
<item><col>col1_value</col><col> col2_value</col><item>
这个xml解读起来
就是同一个column col下面两个不同的values
而你的select是要求读两个columns啊,这两者相差太多
If you think my suggestion is useful, please rate it as helpful.
If it has helped you to resolve the problem, please Mark it as Answer.
http://twitter.com/7Kn1ghts- 已建议为答案 WeiLin QiaoModerator 2011年5月9日 1:37
- 已标记为答案 WeiLin QiaoModerator 2011年5月20日 9:51
全部回复
-
<item><col>col1_value</col><col> col2_value</col><item>
这个xml解读起来
就是同一个column col下面两个不同的values
而你的select是要求读两个columns啊,这两者相差太多
If you think my suggestion is useful, please rate it as helpful.
If it has helped you to resolve the problem, please Mark it as Answer.
http://twitter.com/7Kn1ghts- 已建议为答案 WeiLin QiaoModerator 2011年5月9日 1:37
- 已标记为答案 WeiLin QiaoModerator 2011年5月20日 9:51