Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I made a Query in Mapbasic like :

Dim query As String
query = "Select * from some_table"

How to run query to form table? Is it possible to save selected value in variable without forming table?

share|improve this question
up vote 4 down vote accepted

You can just run the SQL command right in the MapBasic code:

Select * from some_table into mySelection

If you do need to store the SQL query in a string (dynmic SQL string etc) you can execute it using RunCommand

Dim query As String
query = "Select * from some_table into mySelection"
Run Command query 

In order to get the values from the table you need to use Fetch

Dim value as String
Fetch First From mySelection
value = mySelection.{ColumnName}

You will have to write a loop using Fetch First and Fetch Next to loop over all the records to do something with each one.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.