gpt4 book ai didi

sql - 没有得到适当的结构

转载 作者:行者123 更新时间:2023-12-04 05:59:18 27 4
gpt4 key购买 nike

我有这样的存储过程:

CREATE PROCEDURE [dbo].[Poll_EDI834_5010] 
AS
BEGIN
SELECT Header.ST01,
Line.PER04__CommunicationNumber ,
(SELECT Member_Ref.REF01_ReferenceIdentificationQualifier
FROM EDI834_5010_2000_RefLoop Member_Ref
WHERE Member_Ref.Id_Header = Header.BGN02__TransactionSetIdentifierCode
AND Member_Ref.Id_Loop2000 = Line.Member_Id
FOR XML AUTO, ELEMENTS, TYPE),
VLine.HD01_MaintenanceTypeCode,
(SELECT ClaimDTP.DTP01__DateTimeQualifier
FROM EDI834_5010_2300_DTPLoop ClaimDTP
WHERE ClaimDTP.Id_Header = Header.BGN02__TransactionSetIdentifierCode
AND ClaimDTP.Id_Loop2000 = Line.Member_Id
AND ClaimDTP.Id_Loop2300 = VLine.Id_Claim
FOR XML AUTO, ELEMENTS, TYPE)
FROM EDI834_5010_Header Header
JOIN EDI834_5010_2000 Line ON Header.BGN02__TransactionSetIdentifierCode = Line.Header_Id
JOIN EDI834_5010_2300Loop VLine ON Header.BGN02__TransactionSetIdentifierCode = VLine.Id_Header_Id andVLine.Id_Loop2000=Line.Member_Id
FOR XML AUTO, ELEMENTS
END
GO

我得到的数据结构如下:
<Header>
<Line>
<MemberRef> </MemberRef>
<MemberRef> </MemberRef>
<VLine>
<Claim_DTP> </Claim_DTP>
<Claim_DTP> </Claim_DTP>
</VLine>
</Line>
</Header>

我的问题是我希望数据看起来像这样:
  <Header>
<Line>
<MemberRef> </MemberRef>
<MemberRef> </MemberRef>
<VLine>
<Claim_DTP> </Claim_DTP>
<Claim_DTP> </Claim_DTP>
</VLine>
<VLine>
<Claim_DTP> </Claim_DTP>
<Claim_DTP> </Claim_DTP>
</VLine>
</Line>
</Header>

为什么我的 VLine节点不重复?但是当我删除子查询时 Member_Ref我正在获得适当的结构。但我需要那个子查询。有没有办法实现这种结构?

最佳答案

        CREATE PROCEDURE [dbo].[Poll_EDI834_5010]  
AS
BEGIN
SELECT Header.ST01,
Line.PER04__CommunicationNumber ,
(SELECT Member_Ref.REF01_ReferenceIdentificationQualifier
FROM EDI834_5010_2000_RefLoop Member_Ref
WHERE Member_Ref.Id_Header = Header.BGN02__TransactionSetIdentifierCode
AND Member_Ref.Id_Loop2000 = Line.Member_Id
FOR XML AUTO, ELEMENTS, TYPE),
(SELECT VLine.HD01_MaintenanceTypeCode,
(SELECT ClaimDTP.DTP01__DateTimeQualifier
FROM EDI834_5010_2300_DTPLoop ClaimDTP
WHERE ClaimDTP.Id_Header = Header.BGN02__TransactionSetIdentifierCode
AND ClaimDTP.Id_Loop2000 = Line.Member_Id
AND ClaimDTP.Id_Loop2300 = VLine.Id_Claim
FOR XML AUTO, ELEMENTS, TYPE)
FROM EDI834_5010_2300Loop VLine
Where Header.BGN02__TransactionSetIdentifierCode = VLine.Id_Header_Id andVLine.Id_Loop2000=Line.Member_Id

FOR XML AUTO, ELEMENTS, TYPE)
FROM EDI834_5010_Header Header
JOIN EDI834_5010_2000 Line ON Header.BGN02__TransactionSetIdentifierCode = Line.Header_Id
FOR XML AUTO, ELEMENTS
END
GO

关于sql - 没有得到适当的结构,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9122245/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com