> For the complete documentation index, see [llms.txt](https://docs.wirebootstrap.com/orm/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.wirebootstrap.com/orm/stored-procedures/execute.md).

# Execute

To execute a stored procedure using an ORM class, start with the name of the class and then call the `procedure` method.  When finished, use the `execAsync` method to run the stored procedure in the database and return the records as a [WireBootstrap DataTable](https://docs.wirebootstrap.com/wirebootstrap/reference/wire.data/wire.data.datatable).

The following example runs the `Ten Most Expensive Products` stored procedure in the Northwind database and returns the results as a data table.

```javascript
const productsTable = await Ten_Most_Expensive_Products.procedure().execAsync();
```

Note, the `execAsync` method returns a TypeScript `Promise` so the `await` keyword can be used to run the stored procedure asynchronously.

## Parameters

To add parameters to the stored procedure, use the `param` method.

The following example calls the `CustOrderHist` stored procedure using `THEBI` as the value for the `CustomerId` parameter.

```javascript
const orderTable = await CustOrderHist.procedure()
   .param(CustOrderHistParam.CustomerID, "THEBI")
.execAsync();
```

The following example executes a query for the first record in the `Customers` table and then uses the `CustomerId` value from the record as the parameter when running the `CustOrderHist` stored procedure.

```javascript
const customer = await Customers.select().execAsyncFirst();
                
const orderTable = await CustOrderHist.procedure()
    .param(CustOrderHistParam.CustomerID, customer.CustomerID)
    .execAsync();
```

## Typed Results

Stored procedures don't published the schema of their results.  However, the ORM entity has a  data table interface and object class that allow the fields in the results to be added. &#x20;

The naming convention for the data table interface is *I\[entity]DataTable* and *\[entity]Row* for an individual result record.

```javascript
interface ICustOrderHistDataTable extends Omit<IWireDataTable, "Rows"> {
  Rows: Array<CustOrderHistRow>;
}

class CustOrderHistRow {
 
   // add properties here
   
   public myProperty1: string;
   public myProperty2: string;
     
}
```

Once these properties are set on the *Row* class, use the `execAsyncRows` method to return the same data table with each row strongly-typed as *Row* objects.

```javascript
const orderTable = await CustOrderHist.procedure().execAsyncRows();
    
orderTable.Rows((order: CustOrderHistRow) => {
    console.log(order.myProperty1);
});
```
