Hi
I have below data . I have group by itemcode,batch no, warehouse. . In below case Batch no 4330 has 2 records with 2 Bin No I want to concat these 2 records.
| Item Code | Batch No | Bin No | Warehouse Code |
| 8 | 4330 | 242 | 82 |
| 8 | 4330 | 194 | 82 |
| 8 | 6527 | 194 | 82 |
| 8 | 6527 | 242 | 82 |
| 8 | 6648 | 242 | 82 |
| 8 | 7444 | 242 | 82 |
| 8 | 8567 | 242 | 82 |
| 8 | 8987 | 242 | 82 |
| 8 | 9743 | 242 | 82 |
It should display like this
| 8 | 4330 | 242,194 | 82 |
| 8 | 6527 | 194,242 | 82 |
Thanks

Eliana BlakeRank #1,595 · 993 reputationPosted Feb 14, 2025, 3:14 AM EST
Based on the data provided, it seems like you are looking to concatenate the Bin No values for records with the same Item Code, Batch No, and Warehouse Code. This can be achieved through SQL queries using GROUP BY and STRING_AGG functions in databases like SQL Server.
Here's an example of how you can concatenate the Bin No values based on your sample data:
SELECT [Item Code], [Batch No], STRING_AGG([Bin No], ',') AS ConcatenatedBins, [Warehouse Code] FROM YourTableName GROUP BY [Item Code], [Batch No], [Warehouse Code]This query will group the records by Item Code, Batch No, and Warehouse Code while concatenating the Bin No values separated by a comma.
By running this query on your dataset, you should get the desired output where the Bin No values are concatenated for records sharing the same Item Code, Batch No, and Warehouse Code.
If you need further assistance or have a different database system in mind, feel free to provide more details for a more tailored solution.
Muhammad Imran AnsariRank #326 · 7.6K reputationPosted Feb 14, 2025, 5:46 AM EST
Hello Ramco,
In SQL, you can use the
STRING_AGGfunction (in SQL Server 2017+) to concatenate the "Bin No"values for each group. Below is the examples:SELECT Item_Code, Batch_No, Warehouse_Code, STRING_AGG(Bin_No, ',') AS Bin_No FROM your_table GROUP BY Item_Code, Batch_No, Warehouse_Code ORDER BY Item_Code, Batch_No;Good Luck!