Dictionary.AddSQL
-----------------

Adds values to a dictionary via SQL.

| Component | Version | macOS | Windows | Linux | Server | iOS SDK |
|---|---|---|---|---|---|---|
| [Dictionary](component_Dictionary.md) | [5.1](newinversion51.md) | ✅ Yes | ✅ Yes | ✅ Yes | ✅ Yes | ✅ Yes |

MBS( "Dictionary.AddSQL"; DictionaryRef; SQL Statement; FileName { ; Params... } ) 

**MBS**( **"Dictionary.AddSQL";** /\* Adds values to a dictionary via SQL. \*/  
**$DictionaryRef**; /\* The reference number to the dictionary.e.g. $dic \*/   
**$SQL Statement**; /\* SQL Statement as a Text string \*/   
**$FileName**; /\* The target database name. Can be empty to not limit query to one database.e.g. "" \*/   
**$Params...**) /\* Optional; Pass here parameters for SQL.   
One parameter to this function for each parameter you want to pass to the SQL statement.e.g. 123 \*/ 

### Parameters

| Parameter | Description | Example | Flags |
|---|---|---|---|
| DictionaryRef | The reference number to the dictionary. | $dic |  |
| SQL Statement | SQL Statement as a Text string |  |  |
| FileName | The target database name. Can be empty to not limit query to one database. | "" |  |
| Params... | Pass here parameters for SQL.    One parameter to this function for each parameter you want to pass to the SQL statement. | 123 | Optional |

### Result

Returns number of items added or error.

### Description

Adds values to a dictionary via SQL.  
From the result set, the first field is used as key and second field if exists as value.  
Returns error in case of SQL error with error message.  
You don't need to use ORDER BY in SQL as the order in a dictionary is defined by storage which for you means unordered.  
  
This function is currently only supported for FileMaker 11 and newer. If you need it for older versions, please contact us.  
  
This function takes variable number of parameters. Pass as much parameters as needed separated by the semicolon in FileMaker.  
Please repeat Params parameter as often as you need.  
### Examples

Test function:

 # create dictionary   
Set Variable \[ $dic ; Value: MBS ("[Dictionary.Create](DictionaryCreate.md)") \]  
\# add keys and values via SQL   
Set Variable \[ $r ; Value: MBS ("Dictionary.AddSQL"; $dic ; "SELECT TextField, NumberField FROM \\"Test Table\\"") \]  
\# query keys   
Set Variable \[ $keys ; Value: MBS ("[Dictionary.Keys](DictionaryKeys.md)"; $dic ) \]  
\# and values   
Set Variable \[ $values ; Value: MBS ("[Dictionary.ValueForKey](DictionaryValueForKey.md)"; $dic ; "Hello") \]  
\# free   
Set Variable \[ $r ; Value: MBS ("[Dictionary.Release](DictionaryRelease.md)"; $dic ) \]  
Add zip codes for three countries from 3 databases to dictionary:

 MBS ( "Dictionary.AddSQL"; $dic ; "SELECT ('DE' + \\"\_5\_stellige\_PLZ\\"),Ort FROM \\"PLZ Deutschland Konvertiert\\" "; "PLZ Deutschland" ) +  
MBS ( "Dictionary.AddSQL"; $dic ; "SELECT ('AT' + \\"\_4\_stellige\_PLZ\\"),Ort FROM \\"PLZ Österreich Konvertiert\\" "; "PLZ Österreich" ) +  
MBS ( "Dictionary.AddSQL"; $dic ; "SELECT ('CH' + \\"\_4\_stellige\_PLZ\\"),Ort FROM \\"PLZ Schweiz Konvertiert\\" "; "PLZ Schweiz" )  
### See also

- [Dictionary.AddSQLRecord](DictionaryAddSQLRecord.md)
- [Dictionary.AddSQLRecords](DictionaryAddSQLRecords.md)
- [Dictionary.Create](DictionaryCreate.md)
- [Dictionary.Keys](DictionaryKeys.md)
- [Dictionary.Release](DictionaryRelease.md)
- [Dictionary.ToJSON](DictionaryToJSON.md)
- [Dictionary.ValueForKey](DictionaryValueForKey.md)

### Release notes

- **Version 13.2**
    - Fixed a possible memory leak in [Dictionary.AddSQL](https://www.mbsplugins.eu/DictionaryAddSQL.shtml) function.
- **Version 7.4**
    - Added [Dictionary.AddSQLRecord](http://www.mbsplugins.eu/DictionaryAddSQLRecord.shtml)(s) function.

### Blog Entries

- [Data structures in MBS Plugin](https://www.mbsplugins.de/archive/2023-11-27/Data_structures_in_MBS_Plugin/monkeybreadsoftware_blog_filemaker)
- [MBS FileMaker Plugin, version 13.2pr4](https://www.mbsplugins.de/archive/2023-04-25/MBS_FileMaker_Plugin_version_1/monkeybreadsoftware_blog_filemaker)
- [Custom Functions stored in a database](https://www.mbsplugins.de/archive/2021-06-15/Custom_Functions_stored_in_a_d/monkeybreadsoftware_blog_filemaker)
- [Data structures in FileMaker with MBS Plugins](https://www.mbsplugins.de/archive/2017-10-19/Data_structures_in_FileMaker_w/monkeybreadsoftware_blog_filemaker)
- [MBS FileMaker Plugin, version 5.2pr9](https://www.mbsplugins.de/archive/2015-08-01/MBS_FileMaker_Plugin_version_5/monkeybreadsoftware_blog_filemaker)
- [MBS FileMaker Plugin, version 5.1pr1](https://www.mbsplugins.de/archive/2015-03-16/MBS_FileMaker_Plugin_version_5/monkeybreadsoftware_blog_filemaker)

This function checks for a license.

Created 12nd March 2015 , last changed 25th February 2026

  
[Dictionary.AddDictionary](DictionaryAddDictionary.md) - [Dictionary.AddSQLRecord](DictionaryAddSQLRecord.md)

[HTML Version](DictionaryAddSQL.shtml)