Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/sql-server/25.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Sql server 使用带有FOR XML AUTO元素的存储过程更改架构_Sql Server_Xml_Xsd_Sql Server 2008 R2 - Fatal编程技术网

Sql server 使用带有FOR XML AUTO元素的存储过程更改架构

Sql server 使用带有FOR XML AUTO元素的存储过程更改架构,sql-server,xml,xsd,sql-server-2008-r2,Sql Server,Xml,Xsd,Sql Server 2008 R2,现在我得到的是XML格式的模式,如下所示 <Header> <data1> </data1> <Line> <data> </data> <VLine> <data> </data> <LUI></LUI> </Vline> </Line> <

现在我得到的是XML格式的模式,如下所示

<Header>
  <data1> </data1>
  <Line>
      <data> </data>
      <VLine>
            <data> </data>
            <LUI></LUI>
      </Vline>
  </Line>
</Header>
但是我需要在xml中获得这样的模式

<Header>
    <data1> </data1>
    <Line>
       <data> </data>
       <VLine>
          <data> </data>
       </Vline>
       <LUI>
             <data> </data>
       </LUI> 
    </Line>
</Header>

我应该如何更改上面的存储过程以获得这样的模式?

试试这个,我没有测试过,所以可能会有很多输入错误

select *,
       (select *
        from EDI834_5010_2300_DTPLoop VLine
        where Line.REF02_MemberSupplementalIdentifier = VLine.Id_REF02__SubscriberIdentifier and Header.BGN02__TransactionSetIdentifierCode = VLine.Id_BGN02__TransactionSetIdentifierCode
        for xml auto, elements, type),
       (select *
        from EDI834_5010_2300_LUILoop LUI
        where LUI.Id_BGN02__TransactionSetIdentifierCode=Header.BGN02__TransactionSetIdentifierCode and LUI.Id_REF02__SubscriberIdentifier=Line.REF02_MemberSupplementalIdentifier 
        for xml auto, elements, type)
from EDI834_5010_Header Header
  join EDI834_5010_2000 Line 
    on Header.BGN02__TransactionSetIdentifierCode = Line.Id_BGN02__TransactionSetIdentifierCode
for xml auto, elements
用于测试子查询是否有效,并且看起来是否有效

declare @t1 table (id int)
declare @t2 table (id int)
declare @t3 table (id int)

insert into @t1 values (1),(2)
insert into @t2 values (1),(2)
insert into @t3 values (1),(2)

select *,
       (select *
        from @t2 as t2
        where t1.id = t2.id
        for xml auto, elements, type),
       (select *
        from @t3 as t3
        where t1.id = t3.id
        for xml auto, elements, type)
from @t1 as t1
for xml auto, elements
结果:

<t1>
  <id>1</id>
  <t2>
    <id>1</id>
  </t2>
  <t3>
    <id>1</id>
  </t3>
</t1>
<t1>
  <id>2</id>
  <t2>
    <id>2</id>
  </t2>
  <t3>
    <id>2</id>
  </t3>
</t1>

试试这个,我没有测试过,所以可能有很多打字错误

select *,
       (select *
        from EDI834_5010_2300_DTPLoop VLine
        where Line.REF02_MemberSupplementalIdentifier = VLine.Id_REF02__SubscriberIdentifier and Header.BGN02__TransactionSetIdentifierCode = VLine.Id_BGN02__TransactionSetIdentifierCode
        for xml auto, elements, type),
       (select *
        from EDI834_5010_2300_LUILoop LUI
        where LUI.Id_BGN02__TransactionSetIdentifierCode=Header.BGN02__TransactionSetIdentifierCode and LUI.Id_REF02__SubscriberIdentifier=Line.REF02_MemberSupplementalIdentifier 
        for xml auto, elements, type)
from EDI834_5010_Header Header
  join EDI834_5010_2000 Line 
    on Header.BGN02__TransactionSetIdentifierCode = Line.Id_BGN02__TransactionSetIdentifierCode
for xml auto, elements
用于测试子查询是否有效,并且看起来是否有效

declare @t1 table (id int)
declare @t2 table (id int)
declare @t3 table (id int)

insert into @t1 values (1),(2)
insert into @t2 values (1),(2)
insert into @t3 values (1),(2)

select *,
       (select *
        from @t2 as t2
        where t1.id = t2.id
        for xml auto, elements, type),
       (select *
        from @t3 as t3
        where t1.id = t3.id
        for xml auto, elements, type)
from @t1 as t1
for xml auto, elements
结果:

<t1>
  <id>1</id>
  <t2>
    <id>1</id>
  </t2>
  <t3>
    <id>1</id>
  </t3>
</t1>
<t1>
  <id>2</id>
  <t2>
    <id>2</id>
  </t2>
  <t3>
    <id>2</id>
  </t3>
</t1>

欢迎使用StackOverflow:如果您发布代码、XML或数据示例,请在文本编辑器中突出显示这些行,然后单击编辑器工具栏上的“代码示例”按钮{},以很好地格式化和语法突出显示它!欢迎使用StackOverflow:如果您发布代码、XML或数据示例,请在文本编辑器中突出显示这些行,然后单击编辑器工具栏上的“代码示例”按钮{},以很好地格式化和语法突出显示它!谢谢米凯尔·埃里克森。这解决了我的问题。这个查询提供了正确格式的xml…@saurabhmohan很高兴听到这个消息。那么你应该考虑接受这个答案。看看它是如何工作的。谢谢米凯尔·埃里克森。这解决了我的问题。这个查询提供了正确格式的xml…@saurabhmohan很高兴听到这个消息。那么你应该考虑接受这个答案。看看它是如何工作的。