1
<Debtor>
및 <Creditor>
요소가 여러 개 생성되는 것을 방지하는 방법. 다음은 개선해야 할 질문입니다. 기본적으로 <name>
과 <address>
을 모두 <Creditor>
또는 <Debtor>
안에 넣고 Amt
에 따라 CASE
으로 표시해야합니다.사례 내부 SELECT..FOR XML - 여러 요소 피하기
SELECT
(SELECT [Amt/@Curr] = t.Curr
,t.Amt
,[EntryDetails/TxnDetails/PostClassDt] = CASE WHEN Amt < 0 THEN 'debit' END
,[EntryDetails/TxnDetails/PostClassCr] = CASE WHEN Amt >= 0 THEN 'return' END
,[EntryDetails/TxnDetails/Parties/Creditor/Name] = CASE WHEN Amt < 0 THEN Contractor END
,[EntryDetails/TxnDetails/Parties/Debtor/Name] = CASE WHEN Amt >= 0 THEN Contractor END
,[EntryDetails/TxnDetails/Parties/Creditor/Address] = CASE WHEN Amt < 0 THEN [Address] END
,[EntryDetails/TxnDetails/Parties/Debtor/Address] = CASE WHEN Amt >= 0 THEN [Address] END
FROM (VALUES
('EUR', -123.45, 'John Doe','St.John'),
('USD', 456.78, 'Jane Doe', 'St.Jane')
) t (Curr, Amt, Contractor, [Address])
FOR XML PATH('Entry'), TYPE
) [Statement]
FOR XML PATH('Schema'), ROOT('Document')
아래에 표시된 필수 형식입니다. 누구든지 도와 주실 래요?
<Document>
<Schema>
<Statement>
<Entry>
<Amt Curr="EUR">-123.45</Amt>
<EntryDetails>
<TxnDetails>
<PostClassDt>debit</PostClassDt>
<Parties>
<Creditor>
<Name>John Doe</Name>
<Address>St.John</Address>
</Creditor>
</Parties>
</TxnDetails>
</EntryDetails>
</Entry>
<Entry>
<Amt Curr="USD">456.78</Amt>
<EntryDetails>
<TxnDetails>
<PostClassCr>return</PostClassCr>
<Parties>
<Debtor>
<Name>Jane Doe</Name>
<Address>St.Jane</Address>
</Debtor>
</Parties>
</TxnDetails>
</EntryDetails>
</Entry>
</Statement>
</Schema>
</Document>