× 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.



Thank you Birgitta,

We actually went a step further.

Because the aggregations of components can also be described as individual entities, we opted to create individual functions for the aggregations that can be included in any object requiring them. Also to provide a consistent definition and data acquisition that helps to ensure that these objects are the same, regardless of what object is using the aggregation.

So we end up with a CTE where the 1st result is the driver, containing the key values for all of the subsequent calls to the aggregation-level functions. The next result set of the CTE generates the XML, assembling all of the aggregations according to the key from the 1st result set.

I want to thank you for your suggestion and recognize that without the many contributions of yours that I had found online, I would have struggled mightily to get this completed.

Steve Needles

-----Original Message-----
From: MIDRANGE-L [mailto:midrange-l-bounces@xxxxxxxxxxxx] On Behalf Of Birgitta Hauser
Sent: Friday, March 23, 2018 1:10 AM
To: 'Midrange Systems Technical Discussion' <midrange-l@xxxxxxxxxxxx>
Subject: RE: SQL XML Nested Aggregation

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

--
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



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.

As an Amazon Associate we earn from qualifying purchases.

This thread ...


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.