Skip to main content
Solved

Creating array of values from multiple rows

  • February 25, 2025
  • 2 replies
  • 29 views

Albert de Ruiter
Star Blazer L2
Forum|alt.badge.img+4

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

Best answer by Adrian Anderson

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

View original
Did this topic help you find an answer to your question?

2 replies

Forum|alt.badge.img+1

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


Albert de Ruiter
Star Blazer L2
Forum|alt.badge.img+4

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


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings