Skip to main content

Hi all,

Suppose you have 2 tables that relate as 1:n. When joining the tables in a query without filtering, the result will be n rows. 

My requirement is to have just one row returned, with the values of the n-table shown as an array. In SQL Server you could use a query like

SELECT 

    p.PK_ONETEST,

    p.Name,

    p.Description,

    (SELECT 

        c.Name

     FROM ODS.NTEST c

     WHERE c.FK_ONETEST = p.PK_ONETEST

     FOR JSON PATH) AS Children

FROM ODS.ONETEST p

;

resulting in 

My question is if we can also achieve this in one or more steps in One Desktop.

Kind regards,

Albert

Hi Albert.

Great question! There are a few ways to do this. The Representative Creator and Group Aggregator steps can help here.

Attached is a simple plan (see community_dq_1647.zip) that takes two text ‘tables’ as input, joins them and then creates the array of children.

Let me know if this helps.

Kind regards,

Adrian


Hi Adrian,

This is indeed what I am looking for!

So both the Representative Creator and Group Aggregator steps prepare the data, grouping the join result, then the concatenate(If) function does in fact the actual creation of the array. Nice!

Thanks!!!

Kind regards,

Albert


Reply