# 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);
});
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.wirebootstrap.com/orm/stored-procedures/execute.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
