SQL.GetFieldAsText
------------------

Returns field's value as text value; converts if needed.

| Component | Version | macOS | Windows | Linux | Server | iOS SDK |
|---|---|---|---|---|---|---|
| [SQL](component_SQL.md) | [2.6](newinversion26.md) | ✅ Yes | ✅ Yes | ✅ Yes | ✅ Yes | ✅ Yes |

MBS( "SQL.GetFieldAsText"; Command; Field ) 

**MBS**( **"SQL.GetFieldAsText";** /\* Returns field's value as text value; converts if needed. \*/  
**$Command**; /\* The command reference number gained with [SQL.NewCommand](SQLNewCommand.md). \*/   
**$Field**) /\* The name or one based index of the field. \*/ 

### Parameters

| Parameter | Description | Example |
|---|---|---|
| Command | The command reference number gained with [SQL.NewCommand](SQLNewCommand.md). | $Command |
| Field | The name or one based index of the field. | $Field |

### Result

Returns text or error message.

### Description

Returns field's value as text value; converts if needed.  
see also:  
[https://www.sqlapi.com/ApiDoc/class\_s\_a\_field.html](https://www.sqlapi.com/ApiDoc/class_s_a_field.html)  
### Examples

Read field value of field "FirstName" into variable:

 $firstname = MBS ("SQL.GetFieldAsText"; $command ; "FirstName")  
Run a stored procedure:

 # new command for calling our test procedure on a Microsoft SQL Server   
Set Variable \[$command ; MBS ( "[SQL.NewCommand](SQLNewCommand.md)"; $Connection ; "dbo.Test" ) \]  
\# set a parameter   
Set Variable \[$r ; MBS ( "[SQL.SetParamAsNumber](SQLSetParamAsNumber.md)"; $Command ; "Param1"; 7 ) \]  
\# execute query   
Set Variable \[$r ; MBS ( "[SQL.Execute](SQLExecute.md)"; $Command ) \]  
\# fetch first record   
Set Variable \[$r ; MBS ( "[SQL.FetchNext](SQLFetchNext.md)"; $Command ) \]  
\# get result field   
Set Variable \[$result ; MBS ( "SQL.GetFieldAsText"; $Command ; 1 ) \]  
Read null value as empty, otherwise get text:

 If(  
 MBS ("[SQL.GetFieldIsNull](SQLGetFieldIsNull.md)"; $command ; "FieldName");   
 "";  
 MBS ("SQL.GetFieldAsText"; $command ; "FieldName"))  
Extract BLOBs from a Oracle database and store in files:

 Set Variable \[ $Connection ; Value: MBS ("[SQL.NewConnection](SQLNewConnection.md)") \]   
Set Variable \[ $result ; Value: MBS ("[SQL.SetConnectionOption](SQLSetConnectionOption.md)";$Connection ;"OCI8.LIBS";"/Users/test/Downloads/instantclient\_19\_8/libclntsh.dylib") \]   
  
Set Variable \[ $result ; Value: MBS ("[SQL.Connect](SQLConnect.md)";$Connection ;"(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=10.128 .12.150 )(PORT=1521))(CONNECT\_DATA=(SID=STRMTL)))";"User”;"Password";"Oracle") \]   
If \[ MBS ("ISError") \]   
 Show Custom Dialog \[ "Failed to connect"; $result \]   
Else  
 Set Variable \[ $sql ; Value: "SELECT FILE\_NAME, FILE\_DATA, FILE\_DESCRIPTION FROM UPLOADED\_FILE OFFSET 1452000 ROWS FETCH NEXT 10 ROWS ONLY" \]   
 Set Variable \[ $cmd ; Value: MBS ("[SQL.NewCommand](SQLNewCommand.md)"; $Connection ; $sql ) \]   
 If \[ MBS ("ISError") \]   
 Show Custom Dialog \[ "Failed to parse SQL"; $cmd \]   
 Else  
 Set Variable \[ $r ; Value: MBS ("[SQL.Execute](SQLExecute.md)"; $cmd ) \]   
 If \[ MBS ("ISError") \]   
 Show Custom Dialog \[ "Failed to run query"; $r \]   
 Else  
 Set Variable \[ $folderPath ; Value: "/Users/test/Desktop/PDF/folder" \]   
 #   
 Set Variable \[ $r ; Value: MBS ("[SQL.FetchNext](SQLFetchNext.md)"; $cmd ) \]   
 If \[ MBS ("ISError") \]   
 # Failed to get record?  
 Show Custom Dialog \[ $r \]   
 Else If \[ $r = 0 \]   
 # no records found  
 Else  
 Loop  
 # get file name  
 Set Variable \[ $filename ; Value: MBS ("SQL.GetFieldAsText"; $cmd ; "FILE\_NAME") \]   
 # get as BLOB with PDF  
 Set Variable \[ $compressed ; Value: MBS ("[SQL.GetFieldAsContainer](SQLGetFieldAsContainer.md)"; $cmd ; "FILE\_DATA"; $fileName ) \]   
 #   
 # store in field  
 // New Record/Request  
 // Set Field \[ SQL\_API::PDF ; $PDF \]   
 // Commit Records/Requests \[ With dialog: On \]   
 #   
 # write to file  
 Set Variable \[ $filePath ; Value: MBS ("[Path.AddPathComponent](PathAddPathComponent.md)"; $folderPath ; $filename ) \]   
 Set Variable \[ $r ; Value: MBS ("[Container.WriteFile](ContainerWriteFile.md)"; $PDF ; $filePath ) \]   
 #   
 # loop ends after last field  
 Set Variable \[ $r ; Value: MBS ("[SQL.FetchNext](SQLFetchNext.md)"; $cmd ) \]   
 Exit Loop If \[ $r ≠ 1 \]   
 End Loop  
 End If  
 End If  
 Set Variable \[ $r ; Value: MBS ("[SQL.FreeCommand](SQLFreeCommand.md)"; $cmd ) \]   
 End If  
End If  
Set Variable \[ $r ; Value: MBS ("[SQL.FreeConnection](SQLFreeConnection.md)"; $Connection ) \]  
### See also

- [SQL.FreeConnection](SQLFreeConnection.md)
- [SQL.GetFieldAsContainer](SQLGetFieldAsContainer.md)
- [SQL.GetFieldAsDate](SQLGetFieldAsDate.md)
- [SQL.GetFieldAsFloat](SQLGetFieldAsFloat.md)
- [SQL.GetFieldIsNull](SQLGetFieldIsNull.md)
- [SQL.GetFieldsAsJSON](SQLGetFieldsAsJSON.md)
- [SQL.GetParamAsText](SQLGetParamAsText.md)
- [SQL.NewCommand](SQLNewCommand.md)
- [SQL.NewConnection](SQLNewConnection.md)
- [SQL.SetParamAsNumber](SQLSetParamAsNumber.md)

### Example Databases

- [SQL to other databases/DuckDB Query](https://www.mbsplugins.eu/MBS-FileMaker-Plugin-Examples/SQL%20to%20other%20databases/DuckDB%20Query.shtml#1ScriptAnchor_)
- [SQL to other databases/Firebird Query](https://www.mbsplugins.eu/MBS-FileMaker-Plugin-Examples/SQL%20to%20other%20databases/Firebird%20Query.shtml#1ScriptAnchor_)
- [SQL to other databases/Microsoft SQL Execute](https://www.mbsplugins.eu/MBS-FileMaker-Plugin-Examples/SQL%20to%20other%20databases/Microsoft%20SQL%20Execute.shtml#1ScriptAnchor_)
- [SQL to other databases/Microsoft SQL Server Connect](https://www.mbsplugins.eu/MBS-FileMaker-Plugin-Examples/SQL%20to%20other%20databases/Microsoft%20SQL%20Server%20Connect.shtml#1ScriptAnchor_)
- [SQL to other databases/Microsoft SQL Server Query](https://www.mbsplugins.eu/MBS-FileMaker-Plugin-Examples/SQL%20to%20other%20databases/Microsoft%20SQL%20Server%20Query.shtml#1ScriptAnchor_)
- [SQL to other databases/MySQL Query](https://www.mbsplugins.eu/MBS-FileMaker-Plugin-Examples/SQL%20to%20other%20databases/MySQL%20Query.shtml#1ScriptAnchor_)
- [SQL to other databases/ODBC Query](https://www.mbsplugins.eu/MBS-FileMaker-Plugin-Examples/SQL%20to%20other%20databases/ODBC%20Query.shtml#1ScriptAnchor_)
- [SQL to other databases/PostgreSQL Query](https://www.mbsplugins.eu/MBS-FileMaker-Plugin-Examples/SQL%20to%20other%20databases/PostgreSQL%20Query.shtml#1ScriptAnchor_)
- [SQL to other databases/SQLite blob](https://www.mbsplugins.eu/MBS-FileMaker-Plugin-Examples/SQL%20to%20other%20databases/SQLite%20blob.shtml#3ScriptAnchor_)
- [SQL to other databases/SQLite fun](https://www.mbsplugins.eu/MBS-FileMaker-Plugin-Examples/SQL%20to%20other%20databases/SQLite%20fun.shtml#3ScriptAnchor_)

### Blog Entries

- [Connect to DuckDB in FileMaker](https://www.mbsplugins.de/archive/2025-04-10/Connect_to_DuckDB_in_FileMaker/monkeybreadsoftware_blog_filemaker)
- [Connect to Postgres in FileMaker](https://www.mbsplugins.de/archive/2025-04-09/Connect_to_Postgres_in_FileMak/monkeybreadsoftware_blog_filemaker)
- [Tip of the day: Connect to MySQL and run a query](https://www.mbsplugins.de/archive/2017-02-07/Tip_of_the_day_Connect_to_MySQ/monkeybreadsoftware_blog_filemaker)

### FileMaker Magazin

- [Ausgabe 3/2016, Seite 30](https://filemaker-magazin.de/neuigkeit/3883-Appetithappen-FMM_201603)
- [Ausgabe 2/2016, Seite 14](https://filemaker-magazin.de/neuigkeit/3879-Appetithappen-FMM_201602)
- [Ausgabe 1/2016, Seite 29](https://filemaker-magazin.de/neuigkeit/3870-Appetithappen-FMM_201601)

This function is free to use.

Created 18th August 2014 , last changed 25th February 2026

  
[SQL.GetFieldAsPNG](SQLGetFieldAsPNG.md) - [SQL.GetFieldAsTime](SQLGetFieldAsTime.md)

[HTML Version](SQLGetFieldAsText.shtml)