---
url: >-
  /statelake/scripting-reference/functions-and-procedures/database-functions/getsqlvaluefromsource.md
---

# GetSQLValueFromSource

**GetSQLValueFromSource** returns a single value - being the first field in an **aSQL** query.

It is more common to use the function **GetDataSetFromSource** to return multiple values - this saves re-querying the database to retrieve multiple fields from a single record. Please also review [GetDataSetFromSource](/statelake/scripting-reference/functions-and-procedures/database-functions/getdatasetfromsource).

The **SQL** query is executed against a **DB Connection** on the **Source** of the **Map**.

**aDBIndex** indicates which of the **DB Connections** is used based on its zero based index.

Declaration: function GetSQLValueFromSource(const aSQL: string; aDBIndex : integer): variant;

An example follows.

```pascal
procedure OnMapEvent(var Value:Variant);
begin
  Value := GetSQLValueFromSource('select name from dr_accs where accno=1',0);
end;
```
