---
url: /flow/guide/scripting-reference/functions/database/getsqlvaluefromsource.md
---

# GetSQLValueFromSource

## Declaration

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

### Example

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

## Description

Returns a single value being the first field in aSQL query. It is more common to use [GetDataSetFromSource](/flow/guide/scripting-reference/functions/database/getdatasetfromsource) to return multiple values - this saves re-querying the database to retrieve multiple fields from a single record.

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.
