# Concatenate all MU values into a single column?

**URL:** <https://techcommunity.softwareag.com/t/concatenate-all-mu-values-into-a-single-column/100853>\
**Category:** Forum\
**Tags:** Adabas-Natural, Adabas, Adabas-Add-on-Products, SQL-Access, Mainframe-Integration, CONNX\
**Created:** [June 29, 2012, 5:52pm UTC](https://techcommunity.softwareag.com/t/concatenate-all-mu-values-into-a-single-column/100853 "2012-06-29T17:52:28Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![Min\_Chai](https://avatars.discourse-cdn.com/v4/letter/m/71c47a/32.png) [@Min\_Chai](https://techcommunity.softwareag.com/u/Min_Chai)\
**Post date:** [June 29, 2012, 5:52pm UTC](https://techcommunity.softwareag.com/t/concatenate-all-mu-values-into-a-single-column/100853/1 "2012-06-29T17:52:28Z")

</div>

My DB model looks like this (In adabas it is a single file with an MU field in it):

In CONNX, it looks like this:  
table1 - master table

- col1
- col2  
table1-MU1 - this is the child table to table1
- col10

The relationship between table1 and table1-MU1 is 1:many

I like to have a select statement that returns to me a single row of table1 and in each row, I like to have the values of the MU column return to me in comma-delimited value.

For example, table1 has a row with col1 = “Smith” and isn = 1

In table1-MU1, isn\_table1 of 1, I have these rows:

isn\_table1 col10  
1 first  
1 second  
1 third

I would like the select to return this row back to me like this: Smith first,second,third instead of

Smith first  
Smith second  
Smith third

I do not know how to craete a temp varaiable in a select to concatenate or coalesce the values.

The number of rows for each isn in table1 varies so I cannot hardcode col10(1), col10(2), etc.

Please advise.

Thanks,  
Min

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/techcommunity/original/3X/c/d/cd19967bb605d28a72d77eb83a1cae22f3df2eb8.svg) [@system](https://techcommunity.softwareag.com/u/system)\
**Post date:** [June 29, 2012, 6:18pm UTC](https://techcommunity.softwareag.com/t/concatenate-all-mu-values-into-a-single-column/100853/2 "2012-06-29T18:18:26Z")

</div>

You don’t need a temporary variable, check into the CONCAT function,  
in the SQL Gateway User Guide → Chapter 11 (SQL Grammar) → SQL String Functions

---

<div class="post-metadata">

**Author:** ![Min\_Chai](https://avatars.discourse-cdn.com/v4/letter/m/71c47a/32.png) [@Min\_Chai](https://techcommunity.softwareag.com/u/Min_Chai)\
**Post date:** [June 29, 2012, 9:38pm UTC](https://techcommunity.softwareag.com/t/concatenate-all-mu-values-into-a-single-column/100853/3 "2012-06-29T21:38:05Z")

</div>

The concat function would concatenate 3 columns of the same row to form a new value but not to concatenate the value of a column in 3 different rows into a string value. The same goes with a coalesce.

Min

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/techcommunity/original/3X/c/d/cd19967bb605d28a72d77eb83a1cae22f3df2eb8.svg) [@system](https://techcommunity.softwareag.com/u/system)\
**Post date:** [June 29, 2012, 9:59pm UTC](https://techcommunity.softwareag.com/t/concatenate-all-mu-values-into-a-single-column/100853/4 "2012-06-29T21:59:30Z")

</div>

ACE generates two kinds of tables for MUs, the “flattened” form, and a “rotated” table,  
for this concatenation requirement I’d use the flattened form.

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/techcommunity/original/3X/c/d/cd19967bb605d28a72d77eb83a1cae22f3df2eb8.svg) [@system](https://techcommunity.softwareag.com/u/system)\
**Post date:** [July 2, 2012, 9:15am UTC](https://techcommunity.softwareag.com/t/concatenate-all-mu-values-into-a-single-column/100853/5 "2012-07-02T09:15:25Z")

</div>

I have attached an example, which -

a) is based on the EMPLOYEES-NAT FDT (File 11)

b) Uses the CREATE TABLE DESCRIPTION statement to define a TABLE, that rotares the MU-field ‘AZ’  
instead of creating a sub-table.

c) Accesses fields which are NOT NULL, concatenating the MU-Field Values 1 thru 3

[concatenated\_MU.zip](https://techcommunity.softwareag.com/uploads/short-url/ix1DqebQqA5DFOrlvkpo2iuBMVo.zip) (581 Bytes)

---

<div class="post-metadata">

**Author:** ![Min\_Chai](https://avatars.discourse-cdn.com/v4/letter/m/71c47a/32.png) [@Min\_Chai](https://techcommunity.softwareag.com/u/Min_Chai)\
**Post date:** [July 2, 2012, 1:44pm UTC](https://techcommunity.softwareag.com/t/concatenate-all-mu-values-into-a-single-column/100853/6 "2012-07-02T13:44:23Z")

</div>

I understand the possibility of using the FLAT table. Unfortunately this approach requires us to hard code the number of possible values for this MU field. In Natural, we use 191 occurrences where possible to avoid having to adjust the program when occurrence count possibilities change. This approach is ugly but I may not have a choice in this case.

Thanks for your suggestions.

Min

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/techcommunity/original/3X/c/d/cd19967bb605d28a72d77eb83a1cae22f3df2eb8.svg) [@system](https://techcommunity.softwareag.com/u/system)\
**Post date:** [July 2, 2012, 1:52pm UTC](https://techcommunity.softwareag.com/t/concatenate-all-mu-values-into-a-single-column/100853/7 "2012-07-02T13:52:22Z")

</div>

Do you, by any chance, have Adabas Triggers & Stored Procedures available ?

You could then create a trigger that returns the concatenated data without you  
having to mess with it on the “client side”.

---

<div class="post-metadata">

**Author:** ![Min\_Chai](https://avatars.discourse-cdn.com/v4/letter/m/71c47a/32.png) [@Min\_Chai](https://techcommunity.softwareag.com/u/Min_Chai)\
**Post date:** [July 2, 2012, 3:49pm UTC](https://techcommunity.softwareag.com/t/concatenate-all-mu-values-into-a-single-column/100853/8 "2012-07-02T15:49:02Z")

</div>

Using Trigger is a good idea. Let me see how far I can go.

Thanks for all of your help.

Min

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/techcommunity/original/3X/c/d/cd19967bb605d28a72d77eb83a1cae22f3df2eb8.svg) [@system](https://techcommunity.softwareag.com/u/system)\
**Post date:** [July 3, 2012, 7:57am UTC](https://techcommunity.softwareag.com/t/concatenate-all-mu-values-into-a-single-column/100853/9 "2012-07-03T07:57:16Z")

</div>

ANSWER:  
It is not possible to accomplish what you have described via SQL.  
The application will have to build the list of values from the MU and add the commas in between.

QUESTION:  
Is it possible to create a query, which returns only one row  
where the LANG-values are concatenated (comma-delimited)?

```
227 ECKHARDT GER,ENG,FRE,SPA 

```

For example -  
The following query returns 4 rows:

```
SELECT e.ADABAS_ISN, e.NAME, l.LANG 
FROM EMPLOYEES e INNER JOIN EMPLOYEES_LANG l 
ON e.ADABAS_ISN = l.ADABAS_ISN 
WHERE NAME = 'ECKHARDT '   
 
227 ECKHARDT GER 
227 ECKHARDT ENG 
227 ECKHARDT FRE 
227 ECKHARDT SPA

```

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/techcommunity/original/3X/c/d/cd19967bb605d28a72d77eb83a1cae22f3df2eb8.svg) [@system](https://techcommunity.softwareag.com/u/system)\
**Post date:** [April 2, 2021, 3:02pm UTC](https://techcommunity.softwareag.com/t/concatenate-all-mu-values-into-a-single-column/100853/10 "2021-04-02T15:02:06Z")

</div>


