question

Anna Lisa Dierking avatar image
0 Likes"
Anna Lisa Dierking asked Jason Lightfoot commented

copy whole table row

Hello,

is there a command or a way to copy a whole row from one table into another table without using a loop?

Right now I am using a for-loop to get each column individually.

Thanks.

FlexSim 18.1.2
flexsim commands
5 |100000

Up to 12 attachments (including images) can be used with a maximum of 23.8 MiB each and 47.7 MiB total.

1 Answer

Steven Hamoen avatar image
1 Like"
Steven Hamoen answered Jason Lightfoot commented
@Anna Lisa Dierking

Your table is build up with a node structure. Actually every row is a node with subnodes for the columns. So can can copy a row with the createcopy command.

· 9
5 |100000

Up to 12 attachments (including images) can be used with a maximum of 23.8 MiB each and 47.7 MiB total.

Steven Hamoen avatar image Steven Hamoen commented ·

@Anna Lisa Dierking It should look something like this:

treenode origTable = reftable("Table1");
treenode destTable = reftable("Table2");
int rowNo = x; //your rowno
createcopy( rank( origTable, rowNo), rank(destTable, rowNo), 1, 0, 0, 1);
1 Like 1 ·
Anna Lisa Dierking avatar image Anna Lisa Dierking Steven Hamoen commented ·

Thanks alot. That works great :)

0 Likes 0 ·
Anna Lisa Dierking avatar image Anna Lisa Dierking commented ·
@steven.hamoen

Thank you.

Can I do that even if the table row I want to copy is part of the result of a query()? Or do I have to copy the sql result into a temporary global table first?

0 Likes 0 ·
Steven Hamoen avatar image Steven Hamoen Anna Lisa Dierking commented ·
@Anna Lisa Dierking

yes this will only work if the table structure is build up out of nodes and the query is in memory so you have to transform it to a normal table first.

0 Likes 0 ·
Anna Lisa Dierking avatar image Anna Lisa Dierking Steven Hamoen commented ·

@steven.hamoen, Thanks. Could you give me an example on how to use the createcopy command to copy a specific row from one global table as a new row into another global table?

0 Likes 0 ·
sachin T3 avatar image sachin T3 commented ·

hi Steven, i want to do similar thing but I want to copy a specific column from table. How do i do that? please help.

0 Likes 0 ·
Steven Hamoen avatar image Steven Hamoen sachin T3 commented ·

@sachin T3 if you look at the tree structure you will see that copying a column means copying 1 particular node from each row so there is no easy way. You can either do as in the original post just use a for loop or (but I don't know exactly how and what you want to copy) you could also copy the whole table and then delete the columns you don't need (look at the Table class)

0 Likes 0 ·
Jeanette F avatar image Jeanette F ♦♦ sachin T3 commented ·

Hello @sachin T3,

You can easily copy a column. In the following I am copying it to another table.

Table.query("SELECT [Col 1] FROM [GlobalTable1]").cloneTo(Table("GlobalTable2"))
0 Likes 0 ·
Jason Lightfoot avatar image Jason Lightfoot ♦ sachin T3 commented ·

Can you show us your case - ideally in a new question? If the target table already has row values then an update clause on the target table with a join may be necessary.

0 Likes 0 ·