Execute an SQL query and returns the results.
QueryExecute(sql=[String], params=[any], options=[struct])
Argument | Type | Required | Description | Default |
---|---|---|---|---|
sql |
String |
true |
The SQL to execute | |
params |
any |
false |
An array of binding parameters or a struct of named binding parameters | [] |
options |
struct |
false |
A struct of query options |
SQL Only Example. Assumes that a default datasource has been specified (by setting the variable this.datasource in Application.bx)
qryResult = queryExecute("SELECT * FROM Employees");
Use :structKeyName
in your sql then pass a struct with corresponding key names.
qryResult = queryExecute(
"SELECT * FROM Employees WHERE empid = :empid AND country = :country",
{
country="USA",
empid=1
}
);
When passing with an array use the ?
symbol as a placeholder in your sql
qryResult = queryExecute(
"SELECT * FROM Employees WHERE empid = ? AND country = ?",
[
1,
"USA"
]
);