# AEXECUTE
__FORCETOC__
## Description
This function will queue up a query and run it asynchronously in a background thread (rather than the script waiting for it to complete like the [EXECUTE](EXECUTE.md) function). Once the query has been executed, a specified callback function will run.
***Note 1***: An open database connection is required for this function to work correctly. See the [CONNECT](CONNECT.md) function for information regarding the opening of a database connection.
***Note 2***: The [AEXECUTE](AEXECUTE.md) and [EXECUTE](EXECUTE.md) functions are intended to run SQL commands that do not return any results (such as DELETE or UPDATE). For commands that return results (that you want to then read back) see the [AQUERY](AQUERY.md) and [QUERY](QUERY.md) functions.
Valid for the following objects:
* [Database](Database.md)
## Syntax
AEXECUTE *function*, *command*
{| border="1" cellspacing="4" cellpadding="4"
| **Argument** || **Type** || **Description**
|-
| *function* || string || A script function to call when the command has been executed.
{| cellspacing="4" cellpadding="4"
| **Argument** || **Description**
|-
| *ARGN1* || The type of command (0 = [AEXECUTE](AEXECUTE.md), 1 = [AQUERY](AQUERY.md))
|-
| *ARGN2* || 0 = Command failed, 1 = Command succeeded.
|-
| *ARGS* || The command that was executed.
|}
|-
| *command* || string || The SQL command to execute.
|}
## Return Values
This function returns one of two values when executed. See the table below for the meanings of the return values:
{| border="1" cellspacing="4" cellpadding="4"
| **Return Value** || **Description**
|-
| 0 || Command has not been successfully queued.
|-
| 1 || Command has been successfully queued.
|}
## Examples
```
//
// Queues up an SQL command.
//
[FUNCTION f_execute]
SERV.LOG Deleting all rows from table 'tbl_name'.
IF ( == 0)
SERV.LOG Failed to queue command.
ELSE
SERV.LOG Command queued.
ENDIF
RETURN
//
// This function will be called when the query has been executed.
//
[FUNCTION f_execute_callback]
IF ( == 0)
SERV.LOG The command failed to execute. ()
ELSE
SERV.LOG The command succeeded. ()
ENDIF
RETURN
```
[Category: Reference Compendium](Category:_Reference_Compendium.md)
[Category: Properties and Functions](Category:_Properties_and_Functions.md)