Skip to content
Advertisement

Combine different CTE json objects together

I am having difficulties grasping the concept of combining two CTE json objects together. The data from the two are matched by a field WOID, which is the “workOrderID” in this json. I do not know the correct way of going about this.

Needed Results:

This is what is created so far and creates both parts. I just cannot seem to find the correct way to combine them into one json object that I can use in the next step. I am using CTE’s to create each part of the json, starting from the most inner part outward. I am stuck at the point of “Combine the workorder and subtypes”. And maybe this should be done in a step that I have already created; I am not sure?

Here is the data from the files used in the above:

This is the expected json (I think, I am not sure what the subtype record will look like – or should look like when there is no data to show. I would think it would not create anything, but I do not know at this time.)

Advertisement

Answer

Just a demo how it should work.

The query works as is, but it seems that the JSON_ARRAY scalar function is broken at the moment (in 11.5.4.0 & 11.1.4.5), so you need to use these FETCH FIRST clauses (it must work without them) just to get some result (you get various SQLCODE=-901 errors otherwise).
You may open a Case with IBM Support to make it work as needed…

Update

It’s expected, that these bugs will be resolved in upcoming fixpacks for both Db2 versions.

User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement