需要一个select命令,用于将表列值作为属性名称的另一个列值的xml属性(值)获取。 [英] Need a select command for getting table column values into an xml attribute (value) for a another column value as an attribute name.

查看:83
本文介绍了需要一个select命令,用于将表列值作为属性名称的另一个列值的xml属性(值)获取。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好



请帮助输出一个sql命令,该命令将xml作为结果(输出)。下面的例子给你一个关于我的要求的简要信息。



CustNo Pname  Pid

1          Appel    AP

1         橙色   或者

1         芒果    MG

2          Appel    AP

2         橙色   或者

3          Appel    AP





这意味着,我有三列。现在我需要一个来自Sql select命令的下面的xml。



 <  示例 >  
< custNo ID = 1 >
< seq Appel = AP 橙色 = < span class =code-keyword>或 MANGO = MG / >
< / custNo >
< custNo ID = 2 >
< seq Appel = AP < span class =code-attribute>橙色 = / >
< / custNo >
< custNo < span class =code-attribute> ID = 3 >
< seq Appel = AP / >
< / custNo >
< /示例 >







谢谢& Regardes

Chiranjeevi

解决方案

 选择 
custNo.HUEid
,(
选择 [Appel],[Orange],[Mango] 来自
选择 * 来自 hue h 其中 HUEid = custNo.HUEid)p
Pivot(
max(pid) HUENome 中的class =code-keyword>([Appel],[Orange],[Mango])
as seq
对于 xml auto, type

来自 hue custNo
group by hueid
< span class =code-keyword>对于
xml auto,root(' 示例'





这是我使用Pivot和For Xml的T-Sql版本,希望这个帮助= )


 //启动XML文件,回显父节点
echo ' < span class =code-comment>< sample>';

//遍历行,打印XML节点 每个
while


row = @mysql_fetch_assoc(

Hi All

Please help out with an sql command that gives xml as an resultant(output). Below example give you a brief info about my requirement.

CustNo Pname   Pid
1           Appel     AP
1           Orange     OR
1          Mango     MG
2           Appel     AP
2           Orange     OR
3           Appel     AP


that means, i have three columns. Now i need an Below xml from Sql select command.

<Sample>
<custNo  ID="1">
<seq Appel= "AP" Orange="OR" MANGO="MG"/>
</custNo>
<custNo  ID="2">
<seq Appel= "AP" Orange="OR" />
</custNo>
<custNo  ID="3">
<seq Appel= "AP"/>
</custNo>
</Sample>




Thanks & Regardes
Chiranjeevi

解决方案

select
	custNo.HUEid
	,( 
		select [Appel],[Orange],[Mango] from 
		(select *  from hue h where HUEid = custNo.HUEid) p
		Pivot(
		max(pid) for HUENome in ( [Appel],[Orange],[Mango])
		) as seq
		For xml auto  ,type 
	)
 from hue custNo
 group by hueid 
For xml auto ,root ('Sample')



This is my T-Sql version using Pivot and For Xml, hope this help =)


// Start XML file, echo parent node
echo '<sample>';

// Iterate through the rows, printing XML nodes for each
while (


row = @mysql_fetch_assoc(


这篇关于需要一个select命令,用于将表列值作为属性名称的另一个列值的xml属性(值)获取。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆