【发布时间】:2015-11-28 03:45:54
【问题描述】:
我希望表格输出为 XML。我的表格结果是
我需要这样的结果
查询
Declare @colorTable table (Category varchar(100),Attribute varchar(100))
insert into @colorTable values ('Color','Red')
insert into @colorTable values ('Color','Blue')
insert into @colorTable values ('Color','Green')
insert into @colorTable values ('Transport','Bus')
insert into @colorTable values ('Transport','Car')
insert into @colorTable values ('Transport','Twoweeler')
select * from @colorTable
FOR XML PAth(''), ROOT ('xml'), ELEMENTS;
谢谢,
S.桑达
【问题讨论】:
-
到目前为止你有没有尝试过?例如,使用
select ... for xml。 -
是的,我试过了。没有得到我预期的结果
-
如果您将展示您的一些尝试,那么有人可能会指出您所犯的错误。否则它看起来像“请为我写代码”请求。
-
我试过这样
Declare @colorTable table (Category varchar(100),Attribute varchar(100)) insert into @colorTable values ('Color','Red') insert into @colorTable values ('Color','Blue') insert into @colorTable values ('Color','Green') insert into @colorTable values ('Transport','Bus') insert into @colorTable values ('Transport','Car') insert into @colorTable values ('Transport','Twoweeler') select * from @colorTable FOR XML PAth(''), ROOT ('xml'), ELEMENTS;
标签: sql sql-server xml sql-server-2008 stored-procedures