0

I want to print a select query having number of records in text file in mapbasic but no successful results as i am using below code:

Open file "E:\Export.txt" for output as #1
Print #1, select Col1, col2 from table1
close #1
1

You will need a loop to fetch the first row from the query and print it, before moving to the next row and then continuing until the end of the table - EOT() eg:

Select * From table1 Where ... Into my_query
Open file "E:\Export.txt" For Output As #1
Fetch First From my_query
Do While Not EOT(my_query)
    Write #1, my_query.col1, my_query.col2
    Fetch Next From my_query
Loop
Close File #1

The Write #1 statement will automatically add commas between fields. If you don't want this then use Print #1. You might find it easier to export your query as a CSV file. If you manually export a table with the MapBasic window open you will see the syntax required.

  • When i run the code using your given suggestion, window appears that "Mapinfo@professional application file has stopped working". i have to close program. – user514348 Aug 2 '17 at 4:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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