Let's say I have a table called Details
with 4 columns:OrderNo
, Name
, Qty
, and Weight
. I am iterating through the table and selecting the needed fields, concatenating a string out of the data. For example:
-----------------------------------------------------------------
| OrderNo | Name | Qty | Weight |
-----------------------------------------------------------------
| a1234 | HDMI_Cable | 2 | 0.1 |
| a1234 | Aux_Cable | 1 | 0.1 |
| b5346 | 2.1_Speakers | 1 | 3.5 |
| t5485 | 3.5mm_Adapter | 5 | 0.1 |
-----------------------------------------------------------------
So with this data, what I would do is iterate through the table and concatenate the data separated by a semicolon (;), then each row separated by a '>'. For the second and third row, this would give me:
a1234;Aux_Cable;1;0.1>b5346;2.1_Speakers;1;3.5>
The complicated part is that when the order number is the same, I'd like to append it to the previous row without repeating the order number. For example, row 1 and 2 would look like:
a1234;HDMI_Cable;2;0.1;Aux_Cable;1;0.1>
I have tried using IF loops and cases with nested select statements, but I keep running into endless errors and can never seem to get it to work. Anyone have any idea on how to do this or if it can be done? Thanks for reading!