2

I'm having a bit of trouble with the Alias variable in MapBasic. In short, I have a table where I was to group by a specific column. Then I want to run through each unique value from the grouped table through the original one and combine each one. So I have a table of cities with a column of which country each city is in. My program gives the user to choose a table and a column within that table to gorup by. Then it basically goes like this:

Dim aSelection, aGrouped as Alias 
Selection = selectedTable & "." & selectedColumn
Select * from selectedTable into Temp_GroupedTable Group By selectedColumn
aGrouped = Temp_GroupedTable & "." & selectedColumn

So a) is this code correct? b) How can I fetch the data from each row in the Temp_GroupedTable so that I can compare it with the values in the original table? I currently have this general setup within a loop:

Fetch rec i from Temp_GroupedTable
Select * from selectedTable into New_Temp_TAB Where aSelection = aGrouped
Objects Combine

I know there is something wrong... But I don't know how to fix it. Any ideas?

PolyGeo
65.5k29 gold badges115 silver badges350 bronze badges
asked Feb 2, 2016 at 22:19

2 Answers 2

2

Try this:

Dim aSelection, aGrouped as Alias
Dim sGrouped As String
aSelection = selectedTable & "." & selectedColumn
Select * from selectedTable 
 into Temp_GroupedTable 
 Group By aSelection
aGrouped = "Temp_GroupedTable." & selectedColumn
Fetch First from Temp_GroupedTable
Do Until EOT(Temp_GroupedTable)
 aGrouped = sGrouped
 Select * from selectedTable 
 into New_Temp_TAB 
 Where aSelection = sGrouped
‘** Objects Combine ...
 Fetch First from Temp_GroupedTable
Loop

I changed your first selection a bit and also the assignment of the aGrouped alias variable. And then I made some changes to your loop. I’m not entirely sure what more you want to do within the loop.

I’m not entirely sure about this line: Where aSelection = aGrouped

You might need to read the value into a string or numeric value first. But give it a go and let us know

answered Feb 3, 2016 at 15:03
2
  • Thanks @peter. But for some reason I get an error message "Variable or Field Temp_GroupedTable.Region not defined" for the line of code you weren't sure about. I can assure you however that the column does exist. Any ideas on solving this? Commented Feb 4, 2016 at 9:39
  • Yeah, that was what I thought. I have modified the code a bit to get around that issue. Notice that I'm assuming your column is a Char() column in my example Commented Feb 5, 2016 at 9:20
2

Thanks for the help @Peter! I ended up using the following code which did what I needed:

Sub Process
Dim aGrouped as Alias
Print "Object Combiner Loaded!"
Select * from selectedTable into Temp_GroupedTable Group By selectedColumn
Print "Grouping Successful"
'*** Groups by user selected column
aSelection = selectedTable & "." & selectedColumn
Select * from selectedTable 
 into Temp_GroupedTable 
 Group By aSelection
aGrouped = "Temp_GroupedTable." & selectedColumn
Fetch First from Temp_GroupedTable '*** Fetchs first row from grouped table
'*** Runs through table to combine objects by each individual value
Do Until EOT(Temp_GroupedTable)
 sGrouped = aGrouped
 Select * from selectedTable 
 Where aSelection = sGrouped
 Objects Combine Data selectedColumn = sGrouped 'Retains value of 
 'selected column
 Fetch Next from Temp_GroupedTable
Loop
End Sub
answered Feb 8, 2016 at 12:37

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.