Copy data from a column to rows

262 views
Skip to first unread message

Gnanoday Amidalapadu

unread,
Oct 19, 2017, 1:29:04 AM10/19/17
to MapInfo-L
Hello,

I have a table with some equipments with one cable coming in and 4 cables going out. 

At present this is how my Table looks

Equipment         Cable_out
A                        A1
A                        A2
A                        A3
A                        A4
B                        B1
B                        B2
B                        B3
B                        B4

I would like to create a new Table and this is how I want it to look like


Equipment          CableOut1            CableOut2            CableOut3           CableOut4

A                         A1                         A2                         A3                        A4
B                         B1                         B2                         B3                        B4

Could anyone help me with Mapbasic/Mapinfo code for this.

Thank you

Gnanoday

Bob Wright

unread,
Oct 20, 2017, 8:45:15 AM10/20/17
to MapInfo-L
This is more easily accomplished by exporting to Excel, transposing the data there, and then importing the excel file back into MapInfo.  Here is a link that describes the process in FME, but I do not think the bundled FME in MapInfo has all of the functionality of the full version.

Bryn Stevenson

unread,
Oct 20, 2017, 11:39:40 AM10/20/17
to mapi...@googlegroups.com
Is this actual data sample? If the data is consistent you could read each column of each row using loops and insert or update the value into a new or existing row in the new table based upon the column read and it's value.
If all the data in the Cable_Out column follows the same format, check the last character in the value to identify the column to update in the new table.

Bryn Stevenson

unread,
Oct 21, 2017, 8:18:37 PM10/21/17
to MapInfo-L
Attached mb file is how I would solve it based upon your sample data. However, if your Cable_out column data doesn't reference the column it needs to go into the destination table then you'll need to find a way of dealing with that, maybe ensure that your data is sorted in order and add to each column in sequence that each source row is read. Maybe my program will simply point you in the right direction.
Col2Row.mb

Gnanoday Amidalapadu

unread,
Oct 26, 2017, 10:33:57 PM10/26/17
to MapInfo-L
Thank You Bryn and Bob.

I have sorted it out. 
Reply all
Reply to author
Forward
0 new messages