BookmarkSubscribeRSS Feed
Choose Language Hide Translation Bar
Community Trekker

## how to move one row from one table to another table?

Hi, Here i ran into a problem. I have two tables. One is main table which have 847 rows record. It recorded every one min. Now i hope i can click JSL once so that every one min there is one row was automaitically moved from main table to Table 2. That means after 60 mins, there are 60 rows in Table2. 120mins later, there are 120rows in Tables2. Until to the end after 847 mins.

Thanks in advanced.

GMan

1 ACCEPTED SOLUTION

Accepted Solutions
Super User

## Re: how to move one row from one table to another table?

Here is a simplified example of how to do your minute by minute updating.  If you do a little playing with it, you should get what you need

``````Names Default To Here( 1 );
dt = Open( "\$SAMPLE_DATA/Big Class.jmp" );

// Reduce the number of rows to a reasonable number for the test
dt << select rows( {1, 2, 3} );
dt << invert row selection;
dt << delete rows;

// Create the output table
dt2 = New Table( "update",
New Column( "time updated", Format( "d/m/y h:m:s", 17 ) ),
New Column( "Name", character )
);
Wait( 0 );

// Set the initial values
begin = Today();
TheRow = -1; // set to -1 so first row will be immediatly written

// Loop until the minute has changed, then update
While( TheRow + 2 <= N Rows( dt ),
If( Date Difference( begin, Today(), "Minute", "actual" ) > TheRow,
dt2 << Begin Data Update;
dt2 << Add Rows( 1 );
dt2:time updated[N Rows( dt2 )] = Today();
dt2:Name[N Rows( dt2 )] = dt:Name[TheRow + 2];
dt2 << End Data Update;
Wait(55);
TheRow++;
);
// This is optional, but it should reduce the cpu cycle impact if used
Wait(1);
);``````
Jim
2 REPLIES 2
Super User

## Re: how to move one row from one table to another table?

Here is a simplified example of how to do your minute by minute updating.  If you do a little playing with it, you should get what you need

``````Names Default To Here( 1 );
dt = Open( "\$SAMPLE_DATA/Big Class.jmp" );

// Reduce the number of rows to a reasonable number for the test
dt << select rows( {1, 2, 3} );
dt << invert row selection;
dt << delete rows;

// Create the output table
dt2 = New Table( "update",
New Column( "time updated", Format( "d/m/y h:m:s", 17 ) ),
New Column( "Name", character )
);
Wait( 0 );

// Set the initial values
begin = Today();
TheRow = -1; // set to -1 so first row will be immediatly written

// Loop until the minute has changed, then update
While( TheRow + 2 <= N Rows( dt ),
If( Date Difference( begin, Today(), "Minute", "actual" ) > TheRow,
dt2 << Begin Data Update;
dt2 << Add Rows( 1 );
dt2:time updated[N Rows( dt2 )] = Today();
dt2:Name[N Rows( dt2 )] = dt:Name[TheRow + 2];
dt2 << End Data Update;
Wait(55);
TheRow++;
);
// This is optional, but it should reduce the cpu cycle impact if used
Wait(1);
);``````
Jim
Community Trekker

## Re: how to move one row from one table to another table?

Thank you, Jim. With your help, i realized it.