SQL.GetFieldAsNumber
--------------------

Returns field's value as integer number 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.GetFieldAsNumber"; Command; Field ) 

**MBS**( **"SQL.GetFieldAsNumber";** /\* Returns field's value as integer number 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 number or error message.

### Description

Returns field's value as integer number value; converts if needed.  
For float values, you can use [SQL.GetFieldAsFloat](SQLGetFieldAsFloat.md).  
  
see also:  
[https://www.sqlapi.com/ApiDoc/class\_s\_a\_field.html](https://www.sqlapi.com/ApiDoc/class_s_a_field.html)  
  
Improved for MBS Plugin version 12.0 to work for all number types and preserve numeric values.  
### Examples

Reads floating point value from field Count into variable:

 $x = MBS ("SQL.GetFieldAsNumber"; $command ; "Count")  
Reads floating point value from 2nd field into variable:

 $x = MBS ("SQL.GetFieldAsNumber"; $command ; 2)  
Read null value as empty, otherwise get number:

 If(  
 MBS ("[SQL.GetFieldIsNull](SQLGetFieldIsNull.md)"; $command ; "FieldName");   
 "";  
 MBS ("SQL.GetFieldAsNumber"; $command ; "FieldName"))  
### See also

- [SQL.GetFieldAsDate](SQLGetFieldAsDate.md)
- [SQL.GetFieldAsFloat](SQLGetFieldAsFloat.md)
- [SQL.GetFieldAsTime](SQLGetFieldAsTime.md)
- [SQL.GetFieldIsNull](SQLGetFieldIsNull.md)
- [SQL.GetParamAsNumber](SQLGetParamAsNumber.md)
- [SQL.NewCommand](SQLNewCommand.md)

### Release notes

- **Version 12.0**
    - Added [SQL.GetFieldAsNumber](https://www.mbsplugins.eu/SQLGetFieldAsNumber.shtml), [SQL.GetParamAsNumber](https://www.mbsplugins.eu/SQLGetParamAsNumber.shtml) and [SQL.SetParamAsNumber](https://www.mbsplugins.eu/SQLSetParamAsNumber.shtml) to better handle numeric values.
- **Version 7.3**
    - Changed [SQL.GetFieldAsNumber](http://www.mbsplugins.eu/SQLGetFieldAsNumber.shtml) and [SQL.GetParamAsNumber](http://www.mbsplugins.eu/SQLGetParamAsNumber.shtml) to return numbers outside 32-bit integer as text.

### Example Databases

- [SQL to other databases/MySQL example](https://www.mbsplugins.eu/MBS-FileMaker-Plugin-Examples/SQL%20to%20other%20databases/MySQL%20example.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 an external database server in FileMaker](https://www.mbsplugins.de/archive/2022-03-11/Connect_to_an_external_databas/monkeybreadsoftware_blog_filemaker)
- [MBS FileMaker Plugin, version 11.6pr1](https://www.mbsplugins.de/archive/2021-12-01/MBS_FileMaker_Plugin_version_1/monkeybreadsoftware_blog_filemaker)
- [MBS FileMaker Plugin, version 7.3pr5](https://www.mbsplugins.de/archive/2017-07-10/MBS_FileMaker_Plugin_version_7/monkeybreadsoftware_blog_filemaker)
- [MBS FileMaker Plugin, version 7.3pr1](https://www.mbsplugins.de/archive/2017-06-05/MBS_FileMaker_Plugin_version_7/monkeybreadsoftware_blog_filemaker)

### FileMaker Magazin

- [Ausgabe 2/2022, Seite 28](https://filemaker-magazin.de/neuigkeit/4174-Appetithappen-FMM_202202)

This function is free to use.

Created 18th August 2014 , last changed 16th November 2021

  
[SQL.GetFieldAsJPEG](SQLGetFieldAsJPEG.md) - [SQL.GetFieldAsPDF](SQLGetFieldAsPDF.md)

[HTML Version](SQLGetFieldAsNumber.shtml)