---
title: "Lusid.Execution.Writer"
slug: "lusidexecutionwriter"
updated: 2024-08-21T10:28:16Z
published: 2024-08-21T10:28:16Z
canonical: "support.lusid.com/lusidexecutionwriter"
---

> ## Documentation Index
> Fetch the complete documentation index at: https://support.lusid.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Lusid.Execution.Writer

| **Type** | **Read/write** | **Author** | **Availability** |
| --- | --- | --- | --- |
| [Data provider](/v1/docs/what-are-a-data-provider-and-a-direct-provider) | Write | FINBOURNE | Provided with LUSID |

Providing you have sufficient [access control permissions](/v1/docs/creating-policies-to-control-access-to-providers-for-different-luminesce-end-users), the `Lusid.Execution.Writer` provider enables you to write a [Luminesce SQL query](/v1/docs/understanding-the-luminesce-sql-query-syntax) that either upserts or deletes [executions](/v1/docs/what-is-an-execution-in-lusid) in LUSID.

> **Note**: By default, `Lusid.Execution.Writer` cannot add properties to executions. To do this, you must first configure `Lusid.Execution.Writer` to 'inline' properties. [See how to do this](/v1/docs/how-do-i-configure-luminesce-entity-providers-to-readwrite-properties).

You must construct a valid table of data to write, one execution per record. `Lusid.Execution.Writer` lists the fields (columns) available to populate with values for each record, and has a set of parameters to help you construct a valid table.

Your query can use the `WriteAction` field to perform one of the following operations:

- Upsert an execution; that is, create an execution in LUSID if it does not exist, and update it if it does. This is the default operation if you omit `WriteAction`.
- Delete an execution.

**See also:** [Lusid.Execution](/v1/docs/lusidexecution)

## Basic usage

```sql
@table_of_data = <select-statement>;
select * from Lusid.Execution.Writer where toWrite = @table_of_data;
```

## Query parameters

`Lusid.Execution.Writer` has parameters that help you construct a valid table of data to write.

> **Note:** The `ToWrite` parameter is mandatory and used to actually write the table of data into LUSID.

To list available parameters, their data types, default values, and an explanation for each, run the following query using a [suitable tool](/v1/docs/what-tools-are-available-to-write-luminesce-queries):

```sql
select FieldName, DataType, ParamDefaultValue, Description from Sys.Field where TableName = 'Lusid.Execution.Writer' and FieldType = 'Parameter';
```

## Data fields

`Lusid.Execution.Writer` lists the fields you can populate in your table of data to write.

Depending on the operation you want to perform, the following fields are mandatory to include in the table of data:

| **Operation** | **Specify using...** | **Mandatory fields** |
| --- | --- | --- |
| Upsert | `'Upsert' as WriteAction` (or omit) | `ExecutionScope` `ExecutionCode` `RelatedPlacementScope` `RelatedPlacementCode` `State` `Side` `Type` `CreatedDate` `Currency` `SettlementCurrency` `Counterparty` |
| Delete | `'Delete' as WriteAction` | `ExecutionScope` `ExecutionCode` |

To list all available fields, their data types, whether fields are considered 'main', and an explanation for each, run the following query using a [suitable tool](/v1/docs/what-tools-are-available-to-write-luminesce-queries):

```sql
select FieldName, DataType, IsMain, IsPrimaryKey, SampleValues, Description from Sys.Field where TableName = 'Lusid.Execution.Writer' and FieldType = 'Column';
```

## Write errors

We recommend examining the results of every write query using one or more of the `WriteError`, `WriteErrorCode` and `WriteErrorDetail` fields.

For each record in the table of data to write, `Lusid.Execution.Writer` returns an error code. If the operation is successful, the error code is `0`. If unsuccessful, a positive error code and explanation help you discover why LUSID considers the operation invalid.

## Examples

> **Note:** For more example Luminesce SQL queries, visit our [Github repo](https://github.com/finbourne/luminesce-examples/tree/master/examples).

### Example 1: Create an execution record

Upsert is the default operation if you omit the `WriteAction` field.

```sql
@data_to_write = select 'Finbourne-Examples' as ExecutionScope, 'EXECUTION-1' as ExecutionCode, 'Finbourne-Examples' as RelatedPlacementScope, 
'PLACEMENT-1' as RelatedPlacementCode, 'Filled' as State, 'Buy' as Side, 'Market' as Type, #2023-08-01# as CreatedDate, 'GBP' as Currency, 'GBP' as SettlementCurrency, 
'Broker_A' as Counterparty, 50 as Quantity, 60 as AveragePrice, 'LUID_ABCDEFGH' as LusidInstrumentId;
select * from Lusid.Execution.Writer where ToWrite = @data_to_write;
```

### Example 2: Create multiple records of executions in the same scope

```sql
@@scope = select 'Finbourne-Examples';
@@created = select #2023-08-01#;
@@currency = select 'GBP';

@executions = values
('EXECUTION-A', 'PLACEMENT-A', 'Filled', 'Buy', 'Limit', 'Broker_A', 40, 95, 'LUID_00003DDL'),
('EXECUTION-B1', 'PLACEMENT-B', 'Filled', 'Buy', 'Market', 'Broker_B', 44, 110, 'LUID_00003DCH'),
('EXECUTION-B2', 'PLACEMENT-B', 'Filled', 'Buy', 'Market', 'Broker_B', 20, 112, 'LUID_00003DCH');

@data_to_write = select @@scope as ExecutionScope, column1 as ExecutionCode, @@scope as RelatedPlacementScope, column2 as RelatedPlacementCode, column3 as State, 
column4 as Side, column5 as Type, @@created as CreatedDate, @@currency as Currency, @@currency as SettlementCurrency, column6 as Counterparty, column7 as Quantity, 
column8 as AveragePrice, column9 as LusidInstrumentId from @executions;
select * from Lusid.Execution.Writer where ToWrite = @data_to_write;
```

### Example 3: Delete an execution

```sql
@data_to_write = select 'Finbourne-Examples' as ExecutionScope, 'EXECUTION-1' as ExecutionCode, 'Delete' as WriteAction;
select * from Lusid.Execution.Writer where ToWrite = @data_to_write;
```
