Hello everyone,
 
This is a summary of answers to my query (thank you very much):

I have some attributes tables with the records in this fashion:

Poly_id    Code    Definition        Value
    1           xyz           xyz            xyz
    1           xyz           xyz            xyz
    2           xyz           xyz            xyz
    2           xyz           xyz            xyz
    3
    3
and so forth...

How can I put all five records pertaining to the same polygon (poly_id) in just one row?  For example:

Poly_id    Code1    Definition1    Value1    Code2    Definition2     Value2
    1
    2
    3
    etc.
The tables contain five records for each polygon, so it would be time consuming selecting individually and joining in a new table.  Will appreciate any suggestions.
 
-----------------------------------------------------------------------------------------------------------
From Patrick Phillips:
 
I recommend that you save a copy of your table as an Access Database, or Excel Spreadsheet.  Once in one of these packages it is an easy matter to restructure your data in any manner you wish.  Though MapInfo and MapBasic are powerful tools, Microsoft's Office products are much better suited to an application such as this.
-----------------------------------------------------------------------------------------------------------
From Ahmet Dabanli:
 
Add a new field and give a name such as Row in MB window
 
Update TABLE set ROW = rowid
 
Select * from TABLE where rowid mod 5 = 1  into S1    (5 stands for each 5 record)
Select * from TABLE where rowid mod 5 = 2  into S2   
Select * from TABLE where rowid mod 5 = 3  into S3   
Select * from TABLE where rowid mod 5 = 4  into S4   
Select * from TABLE where rowid mod 5 = 0  into S5   
save all queries s1  to s5 to hard disk
close all and  open them
 
Update S1 set ROW = rowid
Update S2 set ROW = rowid
..
..
Update S5 set ROW = rowid
 
select * from s1,s2 where s1.row = s2.row into s12
select * from s3,s4 where s3.row = s4.row into s34
save s34 and s12
close queries and open s12 and s34
 
select * from s12,s34 where s12.row = s34.row into s1234
save s1234
close query s1234 and open s1234
select * from s1234,s5 where s1234.row = s5.row into s12345
 
Save s12345 and that is all
 
Regards
----------------------------------------------------------------------------------------------------------- 
From Trey Pattillo:
 
Hello,
 
an idea that uses the MB Window instead of writing MapBasic [which your doing anyway]
 
USE A COPY OF YOUR TABLE TO DO THIS!
 
1) restructure the table and add Code2,Definition2,Value2,Code3,...Value5 with same type as original; rename code to code1, definition to definition1, value to value1
 
2) do Options>Show MapBasic Window
 
[note: if Poly_ID is numeric then remove the quotes "2" "3" "4" "5" below, otherwise leave them - character fields]
[note: REPLACE TabName with YOUR Table Name]
 
3) copy/paste this into the MB Window or type it in
 
Select * from TabName order by Poly_ID, Code, Definition, Value into Sorted
Select * from Sorted where Poly_ID="2" into Work
update Work set Code2=Code1, Definition2=Definition1, Value2=Value1
Select * from Sorted where Poly_ID="3" into Work
update Work set Code3=Code1, Definition3=Definition1, Value3=Value1
Select * from Sorted where Poly_ID="4" into Work
update Work set Code4=Code1, Definition4=Definition1, Value4=Value1
Select * from Sorted where Poly_ID="5" into Work
update Work set Code5=Code1, Definition5=Definition1, Value5=Value1
browse * from TabName
 
4) put the cursor at the start of the window
5) hold down shift key and then arrow down lines to highlight them
6) press enter to process all the lines
7) browse the table and make sure that the updates occurred correctly
8) select the lines in the MB Window [see above] and press delete key to remove them
9) copy/paste the following or type it in
 
Select * from TabName where Poly_ID="2" into Work
Delete from Work
Select * from TabName where Poly_ID="3" into Work
Delete from Work
Select * from TabName where Poly_ID="4" into Work
Delete from Work
Select * from TabName where Poly_ID="5" into Work
Delete from Work
 
10) ensure the deletes did happen
11) save your table
12) go to Table>Maintenance and *pack* the table to remove the deleted records, be sure to set Graphics and Data

 

Reply via email to