Solved Can you use code stage to copy content of whole columns to other empty columns in same collection ?

stefanamihaesei

New Member
Hello, I have a collection with around 1000 rows and I need to copy the contents of the, let's say, first three columns, to the last 6 columns. I don't want to use loops because takes a lot of time. Can I use some code stage to do this instead ?
 

sahil_raina_91

Active Member
Hello, I have a collection with around 1000 rows and I need to copy the contents of the, let's say, first three columns, to the last 6 columns. I don't want to use loops because takes a lot of time. Can I use some code stage to do this instead ?

You can use below code to copy paste data from 1 column to another based on column names.
Call this action multiple times to copy paste multiple columns.

INPUTS: InputCollection , Source_Column , Dest_Column
OUTPUTS: OutputCollection

CODE:

For each dr As DataRow in InputCollection.Rows
dr(Dest_Column) = dr(Source_Column)
Next
OutputCollection=InputCollection
 

stefanamihaesei

New Member
Thanks again, Sahil.
Do you also have an idea for the case if I have same value in two columns, to change value in one of the two columns? I'm also using loop for this case but a code stage I think would make it way faster.
 

sahil_raina_91

Active Member
So let's say, for example, that in my collection with 1000 rows, I have some rows which have the same value in column 2 and in column 4. (column 2 = column 4).
When this case appears, the value in column 4 has to be changed to a another, given, value.

Add another Input Data Item Value

CODE:
For each dr As DataRow in InputCollection.Rows
If dr(Dest_Column) = dr(Source_Column)
dr(Dest_Column) = Value
End If
Next
OutputCollection=InputCollection
 
Top