FM.SQL.Text
-----------

Queries text of SQL result.

| Component | Version | macOS | Windows | Linux | Server | iOS SDK |
|---|---|---|---|---|---|---|
| [FM](component_FM.md) [FMSQL](component_FMSQL.md) | [7.0](newinversion70.md) | ✅ Yes | ✅ Yes | ✅ Yes | ✅ Yes | ✅ Yes |

MBS( "FM.SQL.Text"; SQLref { ; FirstRow; LastRow; firstCol; lastCol; rowSeparator; colSeparator } ) 

**MBS**( **"FM.SQL.Text";** /\* Queries text of SQL result. \*/  
**$SQLref**; /\* The reference number returned by [FM.SQL.Execute](FMSQLExecute.md) function. \*/   
**$FirstRow**; /\* Optional; The index of first row.  
Default is 0.e.g. 0 \*/   
**$LastRow**; /\* Optional; The index of last row.  
Default is [FM.SQL.RowCount](FMSQLRowCount.md)-1.e.g. 5 \*/   
**$firstCol**; /\* Optional; The index of first column.  
Default is 0.e.g. 0 \*/   
**$lastCol**; /\* Optional; The index of last column.  
Default is [FM.SQL.FieldCount](FMSQLFieldCount.md)-1.e.g. 6 \*/   
**$rowSeparator**; /\* Optional; The row separator.  
Default is CR.  
Can be more than one character.e.g. Char(13) \*/   
**$colSeparator**) /\* Optional; The column separator.  
Default is tab character.  
Can be more than one character.e.g. Char(9) \*/ 

### Parameters

| Parameter | Description | Example | Flags |
|---|---|---|---|
| SQLref | The reference number returned by [FM.SQL.Execute](FMSQLExecute.md) function. | $SQLRef |  |
| FirstRow | The index of first row.   Default is 0. | 0 | Optional |
| LastRow | The index of last row.   Default is [FM.SQL.RowCount](FMSQLRowCount.md)-1. | 5 | Optional |
| firstCol | The index of first column.   Default is 0. | 0 | Optional |
| lastCol | The index of last column.   Default is [FM.SQL.FieldCount](FMSQLFieldCount.md)-1. | 6 | Optional |
| rowSeparator | The row separator.   Default is CR.   Can be more than one character. | Char(13) | Optional |
| colSeparator | The column separator.   Default is tab character.   Can be more than one character. | Char(9) | Optional |

### Result

Returns text or error.

### Description

Queries text of SQL result.  
You can use this method to quickly get all fields in a given area as text.  
### Examples

Query fields and export as text and CSV:

 Set Variable \[$sql ; Value:MBS ( "[FM.SQL.Execute](FMSQLExecute.md)"; ""; "select \* from Clients")\]  
If \[MBS ("IsError")\]  
 Show Custom Dialog \["SQL error"; $sql \]  
Else  
 Show Custom Dialog \["SQL result"; "got " &amp; MBS ( "[FM.SQL.RowCount](FMSQLRowCount.md)"; $sql ) &amp;" rows with each " &amp; MBS ( "[FM.SQL.FieldCount](FMSQLFieldCount.md)"; $sql ) &amp; " …"\]  
 # Write to text file  
 Set Variable \[$text ; Value:MBS ( "FM.SQL.Text"; $sql )\]  
 Set Variable \[$desktopFolder ; Value:MBS ( "[Folders.UserDesktop](FoldersUserDesktop.md)" )\]  
 Set Variable \[$path ; Value:MBS ( "[Path.AddPathComponent](PathAddPathComponent.md)"; $desktopFolder ; "fields.txt" )\]  
 Set Variable \[$r ; Value:MBS ( "[Text.WriteTextFile](TextWriteTextFile.md)"; $text ; $path ; "UTF8")\]  
 # Write to text file  
 Set Variable \[$text ; Value:MBS ( "[FM.SQL.CSV](FMSQLCSV.md)"; $sql )\]  
 Set Variable \[$path ; Value:MBS ( "[Path.AddPathComponent](PathAddPathComponent.md)"; $desktopFolder ; "fields.csv" )\]  
 Set Variable \[$r ; Value:MBS ( "[Text.WriteTextFile](TextWriteTextFile.md)"; $text ; $path ; "UTF8")\]  
 # Cleanup  
 Set Variable \[$r ; Value:MBS ( "[FM.SQL.Release](FMSQLRelease.md)"; $sql )\]  
End If  
### See also

- [FM.SQL.Execute](FMSQLExecute.md)
- [FM.SQL.Field](FMSQLField.md)
- [FM.SQL.List](FMSQLList.md)
- [FM.SQL.Max](FMSQLMax.md)
- [FM.SQL.Min](FMSQLMin.md)
- [FM.SQL.Sum](FMSQLSum.md)
- [Folders.UserDesktop](FoldersUserDesktop.md)
- [Path.AddPathComponent](PathAddPathComponent.md)
- [SQL.Execute](SQLExecute.md)
- [Text.WriteTextFile](TextWriteTextFile.md)

### Release notes

- **Version 13.0**
    - Changed [FM.SQL.Text](https://www.mbsplugins.eu/FMSQLText.shtml) and [FM.SQL.CSV](https://www.mbsplugins.eu/FMSQLCSV.shtml) functions to return empty text if there are no rows and no row parameter.
- **Version 7.0**
    - Added [FM.SQL.Text](http://www.mbsplugins.eu/FMSQLText.shtml) and [FM.SQL.CSV](http://www.mbsplugins.eu/FMSQLCSV.shtml).

### Blog Entries

- [MBS FileMaker Advent calendar - Door 10 - Minimum and Maximum](https://www.mbsplugins.de/archive/2025-12-10/MBS_FileMaker_Advent_calendar_/monkeybreadsoftware_blog_filemaker)
- [MBS FileMaker Advent calendar - Door 9 - Totals and averages](https://www.mbsplugins.de/archive/2025-12-09/MBS_FileMaker_Advent_calendar_/monkeybreadsoftware_blog_filemaker)
- [MBS FileMaker Advent calendar - Door 7 - Precise entries and their types](https://www.mbsplugins.de/archive/2025-12-07/MBS_FileMaker_Advent_calendar_/monkeybreadsoftware_blog_filemaker)
- [MBS FileMaker Advent calendar - Door 6 - Joins](https://www.mbsplugins.de/archive/2025-12-06/MBS_FileMaker_Advent_calendar_/monkeybreadsoftware_blog_filemaker)
- [MBS FileMaker Advent calendar - Door 5 - Count your field and rows](https://www.mbsplugins.de/archive/2025-12-05/MBS_FileMaker_Advent_calendar_/monkeybreadsoftware_blog_filemaker)
- [MBS FileMaker Advent calendar - Door 4 - FM.SQL.Executeand life in the matrix](https://www.mbsplugins.de/archive/2025-12-04/MBS_FileMaker_Advent_calendar_/monkeybreadsoftware_blog_filemaker)
- [MBS FileMaker Plugin, version 12.6pr2](https://www.mbsplugins.de/archive/2022-12-07/MBS_FileMaker_Plugin_version_1/monkeybreadsoftware_blog_filemaker)
- [FileMaker SQL with Sum, Min, Max and Avg on results](https://www.mbsplugins.de/archive/2019-01-30/FileMaker_SQL_with_Sum_Min_Max/monkeybreadsoftware_blog_filemaker)
- [CSV functions in MBS FileMaker Plugin](https://www.mbsplugins.de/archive/2017-11-01/CSV_functions_in_MBS_FileMaker/monkeybreadsoftware_blog_filemaker)
- [MBS FileMaker Plugin, version 7.0pr2](https://www.mbsplugins.de/archive/2017-01-09/MBS_FileMaker_Plugin_version_7/monkeybreadsoftware_blog_filemaker)

### FileMaker Magazin

- [Ausgabe 3/2018, Seite 34](https://filemaker-magazin.de/neuigkeit/3953-Appetithappen-FMM_201803)

This function checks for a license.

Created 8th January 2017 , last changed 31st March 2023

  
[FM.SQL.Sum](FMSQLSum.md) - [FM.SQL.ToMatrix](FMSQLToMatrix.md)

[HTML Version](FMSQLText.shtml)