Topics   All   Mac OS X (Only)   Windows (Only)   Linux (Only, Not)   iOS (Only, Not)  
Components   Crossplatform Mac & Win   Server   Client   Old   Guides   Examples
New in version: 8.3   8.4   8.5   9.0   9.1   9.2   9.3   9.4   9.5   10.0    Statistic  


Execute the SQL Statement against a FileMaker database.

Component Version macOS Windows Server FileMaker Cloud FileMaker iOS SDK
FM FMSQL 5.1 Yes Yes Yes Yes Yes
MBS( "FM.SQL.Execute"; FileName; SQL Statement { ; Params } )   More


Parameter Description Example value
FileName The target database name. Can be empty to not limit query to one database. ""
SQL Statement SQL Statement as a Text string
Params Optional
Optional, pass here parameters. One parameter to this function for each parameter you want to pass to the SQL statement.


Returns reference number or error.


Execute the SQL Statement against a FileMaker database.
This function requires FileMaker 11 or newer. Please use FM.ExecuteSQL on FileMaker 10 or older.
Returns a SQL Reference, so you can use functions like FM.SQL.RowCount, FM.SQL.FieldCount, FM.SQL.Field and FM.SQL.FieldType to query result. Don't forget to use FM.SQL.Release to release the result from memory when you are done with it.


Query only first row:

MBS( "FM.SQL.Execute"; ""; "SELECT * FROM ProductImages FETCH FIRST 1 ROWS ONLY")

SELECT records

MBS("FM.SQL.Execute"; ""; "select * from Contacts")

Select with parameter:

MBS("FM.SQL.Execute"; ""; "select Menge from Boxen where Artikel_Nr=? ORDER BY Menge DESC"; "ABC123")

Query some values:

Set Variable [$sql; Value:MBS( "FM.SQL.Execute"; ""; "select * from Clients")]
If [MBS("IsError")]
    Show Custom Dialog ["SQL error"; $sql]
    Show Custom Dialog ["SQL result"; "got " & MBS( "FM.SQL.RowCount"; $sql ) &" rows with each " & MBS( "FM.SQL.FieldCount"; $sql ) & " …"]
    Set Variable [$r; Value:MBS( "FM.SQL.Release"; $sql )]
End If

Query record as JSON:

Let ( [
fields = MBS( "FM.QueryFieldsForTableName"; "Contacts");
Records = MBS( "FM.SQL.Execute"; ""; "SELECT \"" & substitute(fields; ¶; "\", \"") & "\" FROM \"Contacts\" WHERE \"First\" = ?"; "Joe");

json = MBS( "FM.SQL.JSONRecord"; Records; 0; fields);
r = MBS( "FM.SQL.Release"; Records )]
; json )

Make a JSON query in one Let statment:

Let (
        $sdat = "10/1/2019 00:00";
        $edat = "10/10/2019 00:00";
        sku = "'PARbh50','PARgy50'";
        sql1 = MBS("FM.SQL.Execute"; ""; "Select docnum,linetotal,db from \"MyTable\" where ItemCode in (" & sku & ") and DocDate between ? and ?"; $sdat; $edat);
        json = MBS( "FM.SQL.JSONRecords"; sql1; "DocNum¶LineTotal¶DB"; 1);
        r = MBS( "FM.SQL.Release"; sql1 )
    ] ; json

See also

Example Databases

Blog Entries

Release notes

Created 18th April 2015, last changed 16th December 2019

FM.SQL.CSV   -   FM.SQL.Field

Feedback: Report problem or ask question.

MBS Xojo Plugins