I need to concat data of columns of rows that have same comparing column values

Peruka, Sikander reddy 155 Reputation points
2024-03-29T20:43:29.7533333+00:00

I need to concatenate data of columns of rows that have same comparing column value.

--Input Data

Number Code

100 A

100 B

100 C

200 X

200 Y

--Output Data

Number Code

100 A|B|C

200 X|Y

Azure Synapse Analytics
Azure Synapse Analytics
An Azure analytics service that brings together data integration, enterprise data warehousing, and big data analytics. Previously known as Azure SQL Data Warehouse.
5,380 questions
Azure Data Factory
Azure Data Factory
An Azure service for ingesting, preparing, and transforming data at scale.
11,655 questions
{count} votes

Accepted answer
  1. AnnuKumari-MSFT 34,556 Reputation points Microsoft Employee Moderator
    2024-04-01T06:26:10.92+00:00

    Hi Peruka, Sikander reddy ,

    Welcome to Microsoft Q&A platform and thanks for posting your query here.

    As per my understanding , you are trying to perform data transformation using mapping dataflow.

    Kindly follow the below steps to achieve the above requirement:

    1. Add source transformation pointing to the input file.

    User's image

    1. Add aggregate transformation to group by the number column.

    User's image

    Data preview: User's image

    1. Add derived column transformation and use below expression to convert array objects ["A","B","C"] into A|B|C :
    ltrim(toString(reduce(Code,'', #acc + '|'+ #item, #result)),'|')
    

    User's image

    Data preview: User's image

    Hope it helps. Kindly accept the answer by clicking on Accept answer button. Thankyou

    2 people found this answer helpful.

1 additional answer

Sort by: Most helpful
  1. Erland Sommarskog 121.9K Reputation points MVP Volunteer Moderator
    2024-03-29T20:54:55.95+00:00

    Use the STRING_AGG function:

    SELECT Number, STRING_AGG(Code, '|') WITHIN GROUP (ORDER BY Code)
    FROM   tbl
    GROUP BY Number
    

    This works on a dedicated pool (I just tested). I cannot vouch for that it will work in a serverless pool.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.