× The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.



I'd split the SQL-Statement into different Common Table Expressions, where
you build the elements and aggregated XML information an join the result
together.

The following example (Multiple Orders with multiple Positions each)
includes 2 XMLAGGregates

With Positions as (Select Company, OrderNo,
XMLAgg(XMLElement(Name "OrderPos",
OrderPos,
XMLForest(ItemNo as "ItemNo",
OrderQty as
"OrderQty"))) XMLPos
From OrderDetx
Group By Company, OrderNo),
Orders as (Select XMLElement(Name "OrderNo", h.OrderNo, XMLPos)
XMLOrder
from OrderHdrX h join Positions p on h.company =
p.Company
and h.OrderNo =
p.OrderNo
where Deldate Between '2018-03-01' and '2018-03-31')

Select XMLElement(Name "Root", XMLAgg(XMLOrder))
from Orders;

Mit freundlichen Grüßen / Best regards

Birgitta Hauser

"Shoot for the moon, even if you miss, you'll land among the stars." (Les
Brown)
"If you think education is expensive, try ignorance." (Derek Bok)
"What is worse than training your staff and losing them? Not training them
and keeping them!"
?Train people well enough so they can leave, treat them well enough so they
don't want to.? (Richard Branson)


-----Original Message-----
From: MIDRANGE-L <midrange-l-bounces@xxxxxxxxxxxx> On Behalf Of Steve
Needles
Sent: Donnerstag, 22. März 2018 23:39
To: Midrange Systems Technical Discussion <midrange-l@xxxxxxxxxxxx>
Subject: SQL XML Nested Aggregation

Hey all,

I've got to generate an XML that has nested Aggregation levels.

<Thing>
<Levels>
<Level>
<Stuff></Stuff>
<NextLevels>
<NextLevel></NextLevel>
<NextLevel></NextLevel>
</NextLevels >
</Level>
<Level>
<Stuff></Stuff>
<NextLevels>
<NextLevel></NextLevel>
<NextLevel></NextLevel>
</NextLevels >
</Level>
</Levels>
<Thing>

Something like below won't work because the syntax won't allow nested
XMLAGG().

SELECT
XMLELEMENT(name "Levels",
XMLELEMENT(name "Stuff",column1),
XMLAGG(LevelsXML
XMLELEMENT(name "NextLevels",
XMLAGG(NextLevelXML)
)
)
)
FROM LevelsXML
Join NextLevelXML using(key1, key2)
GROUP BY Key1, Key2;

Does anyone have an idea of how to pull this off?


Steve Needles




CONFIDENTIAL: The information contained in this email communication is
confidential information intended only for the use of the addressee.
Unauthorized use, disclosure or copying of this communication is strictly
prohibited and may be unlawful. If you have received this communication in
error, please notify us immediately by return email and destroy all copies
of this communication, including all attachments.
--
This is the Midrange Systems Technical Discussion (MIDRANGE-L) mailing list
To post a message email: MIDRANGE-L@xxxxxxxxxxxx To subscribe, unsubscribe,
or change list options,
visit: https://lists.midrange.com/mailman/listinfo/midrange-l
or email: MIDRANGE-L-request@xxxxxxxxxxxx Before posting, please take a
moment to review the archives at https://archive.midrange.com/midrange-l.

Please contact support@xxxxxxxxxxxx for any subscription related questions.

Help support midrange.com by shopping at amazon.com with our affiliate link:
http://amzn.to/2dEadiD


As an Amazon Associate we earn from qualifying purchases.

This thread ...

Replies:

Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.