# wire.data.StoredProcedure

## Parameter Class

| Property  | Type             | Description                                                                                 |
| --------- | ---------------- | ------------------------------------------------------------------------------------------- |
| EventName | string           | Parameter name alias used to map a parameter to another parameter or field in another query |
| Name      | string           | Parameter name                                                                              |
| Value     | string \| number | Parameter value                                                                             |

## Properties

| Name   | Type   | Default | Description                                           |
| ------ | ------ | ------- | ----------------------------------------------------- |
| Name   | object | null    | The name of the stored procedure in the data service. |
| Params | \[ ]   | null    | An array of parameters for the stored procedure.      |

## Methods

| Name                | Description                                                                                                                   |
| ------------------- | ----------------------------------------------------------------------------------------------------------------------------- |
| cast                | Static method that casts an object with the same stored procedure properties into an instance of the `StoredProcedure` class. |
| eventName           | Adds an event name to a parameter                                                                                             |
| getParam(param)     | Returns the parameter object named `param`.                                                                                   |
| param(param, value) | Adds a value to a parameter using the chained method `procedure`.                                                             |

If a service provider supports executing stored procedures, it will set the [allow.storedProcedure](https://docs.wirebootstrap.com/wirebootstrap/reference/wire.data.datasource#allow) attribute to `true`.

```javascript
const allowSprocs = accountService.allow().storedProcedure;
```

The following creates a new `StoredProcedure` object which will call the  stored procedure `spGetUsers` in the data service with a parameter `User` equal to `apeters`.

```javascript
const proc = wire.data.procedure("spGetUsers")
    .param("User", "apeters");
```

The following gets the stored procedure parameter object `UserName`.

```javascript
const param = proc.getParam("UserName");
```

The following is a [TypeScript](https://www.typescriptlang.org) example that executes the stored procedure in the data service.

```javascript
...

const dataTable = await accountService.execAsync(proc);
```

Visit [Creating Queries - Stored Procedures](https://docs.wirebootstrap.com/wirebootstrap/creating-queries/stored-procedures) for more details and examples.
