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

# GetDataSetFromSource

This function is commonly used with **SQL** statements that return a dataset e.g. Select or Exec (when procedure returns a dataset).

This function creates a dataset populated with the results of an **aSQL** query.

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

The dataset starts populated with data from the results of the **SQL** query, and you can work with those records as necessary.

Refer to Dataset Class (TDataset) for information on what you can do with the dataset.

Declaration: procedure GetDataSetFromSource(const aDataSet : TFloClientDataSet; const aSQL: string; aDBIndex : Integer);

**aDataSet** should be a **Global Dataset**.

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

Example

```pascal
procedure OnMapEvent(var Value:Variant);
begin
 //create dataset
  GetDataSetFromSource(Data1,'select accno,name from dr_accs',0);

 //read a value from the dataset
  Value := Data1['Name'].Value;
end;
```
