| Components | All | New | MacOS | Windows | Linux | iOS | ||||
| Examples | Mac & Win | Server | Client | Guides | Statistic | FMM | Blog | Deprecated | Old | |
SQL.FetchNext
Fetches next row from a result set.
| Component | Version | macOS | Windows | Linux | Server | iOS SDK |
| SQL | 2.6 | ✅ Yes | ✅ Yes | ✅ Yes | ✅ Yes | ✅ Yes |
MBS( "SQL.FetchNext"; Command ) More
Parameters
| Parameter | Description | Example |
|---|---|---|
| Command | The command reference number gained with SQL.NewCommand. | $Command |
Result
Returns 0, 1 or error message.
Description
Fetches next row from a result set.Use FetchNext method to fetch row by row from the result set. You need to call it a first time to get to first row after you made a query.
To check whether a result set exists use SQL.isResultSet method.
Result is 1 on success or 0 on failure.
Examples
Fetch next record:
MBS("SQL.FetchNext"; $Command)
Run command and fetch first record
# create command
Set Variable [ $Command ; Value: MBS("SQL.NewCommand"; $Connection; "SELECT * FROM Test")]
# run select
Set Variable [ $result2 ; Value: MBS("SQL.Execute"; $Command)]
# go to first row
Set Variable [ $result3 ; Value: MBS("SQL.FetchNext"; $Command)]
# $result3 is 1 if we got a record
# read first name field from result:
Set Variable [ $firstname ; Value: MBS("SQL.GetFieldAsText"; $command; "FirstName")]
# later release command
Set Variable [ $r ; Value: MBS("SQL.FreeCommand"; $Command)]
Set Variable [ $Command ; Value: MBS("SQL.NewCommand"; $Connection; "SELECT * FROM Test")]
# run select
Set Variable [ $result2 ; Value: MBS("SQL.Execute"; $Command)]
# go to first row
Set Variable [ $result3 ; Value: MBS("SQL.FetchNext"; $Command)]
# $result3 is 1 if we got a record
# read first name field from result:
Set Variable [ $firstname ; Value: MBS("SQL.GetFieldAsText"; $command; "FirstName")]
# later release command
Set Variable [ $r ; Value: MBS("SQL.FreeCommand"; $Command)]
Run a stored procedure:
# new command for calling our test procedure on a Microsoft SQL Server
Set Variable [$command; MBS( "SQL.NewCommand"; $Connection; "dbo.Test" ) ]
# set a parameter
Set Variable [$r; MBS( "SQL.SetParamAsNumber"; $Command; "Param1"; 7 ) ]
# execute query
Set Variable [$r; MBS( "SQL.Execute"; $Command ) ]
# fetch first record
Set Variable [$r; MBS( "SQL.FetchNext"; $Command ) ]
# get result field
Set Variable [$result; MBS( "SQL.GetFieldAsText"; $Command; 1 ) ]
Set Variable [$command; MBS( "SQL.NewCommand"; $Connection; "dbo.Test" ) ]
# set a parameter
Set Variable [$r; MBS( "SQL.SetParamAsNumber"; $Command; "Param1"; 7 ) ]
# execute query
Set Variable [$r; MBS( "SQL.Execute"; $Command ) ]
# fetch first record
Set Variable [$r; MBS( "SQL.FetchNext"; $Command ) ]
# get result field
Set Variable [$result; MBS( "SQL.GetFieldAsText"; $Command; 1 ) ]
See also
- SQL.Connect
- SQL.Execute
- SQL.FetchLast
- SQL.GetFieldNameList
- SQL.GetFieldsAsJSON
- SQL.GetRecordsAsText
- SQL.isResultSet
- SQL.NewCommand
- SQL.NewConnection
- SQL.SetParamAsNumber
Example Databases
- SQL to other databases/DuckDB Query
- SQL to other databases/Firebird Query
- SQL to other databases/Microsoft Access Execute
- SQL to other databases/Microsoft SQL Execute
- SQL to other databases/Microsoft SQL Server Query
- SQL to other databases/MySQL Query
- SQL to other databases/ODBC Query
- SQL to other databases/PostgreSQL Query
- SQL to other databases/SQLite blob
- SQL to other databases/SQLite fun
Blog Entries
- Connect to DuckDB in FileMaker
- Connect to Postgres in FileMaker
- Insert and return new record ID
- Connect to an external database server in FileMaker
- Tip of the day: Connect to MySQL and run a query
FileMaker Magazin
This function is free to use.
Created 18th August 2014, last changed 25th February 2026
MarkDown version: SQLFetchNext.md