# Export SQL Table to CSV Using Flow

appRules features an unmatched number of options for migrating, replicating and synchronizing data. &#x20;

## Product & Hosting Options

#### Platform Product Availability

The workflow activities and other modules used in this sample project are available in the following appRules Platform products:

<table><thead><tr><th width="374"> Platform Product</th><th>Availability</th></tr></thead><tbody><tr><td>appRules Data Migration Engine</td><td><img src="https://1923141441-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MFjmFrZ8sef1J7qkr6H%2Fuploads%2FbZcAZuTcLW9DTTX2Y0n1%2Fimage.png?alt=media&#x26;token=612e0de2-56f8-4c29-8fcc-b96886efccfe" alt=""></td></tr><tr><td>appRules Integration &#x26; Automation Engine</td><td><img src="https://1923141441-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MFjmFrZ8sef1J7qkr6H%2Fuploads%2FKIlgGKdWXgH8Ib3i4LyV%2Fimage.png?alt=media&#x26;token=7c679f36-3408-4ef6-9eaf-690f8c58c5af" alt=""></td></tr><tr><td>appRules Enterprise 360</td><td><img src="https://1923141441-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MFjmFrZ8sef1J7qkr6H%2Fuploads%2FbYAbg5056fkAJrta4voJ%2Fimage.png?alt=media&#x26;token=121aa2c3-4a84-4748-b370-cc73ff6e8f07" alt=""></td></tr></tbody></table>

#### Hosting & Execution Environment&#x20;

If you are running the On-Premise, Azure Marketplace or AWS Marketplace editions, the following hosting options supported by appRules are recommended for running this sample project:

| Hosting Option        | Recommended for Project                                                                                                                                                                                             |
| --------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| IIS                   | ![](https://1923141441-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MFjmFrZ8sef1J7qkr6H%2Fuploads%2FQGuJStnndRXh9p477KCi%2Fimage.png?alt=media\&token=9e62c85b-8107-4880-8911-60a7f11985f8) |
| appRules Host Service | ![](https://1923141441-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MFjmFrZ8sef1J7qkr6H%2Fuploads%2Fg7FiSjSFDMM4rb9C79m9%2Fimage.png?alt=media\&token=688d46b8-261f-4de0-9db7-0a0fbc5e8016) |
| appRules Desktop      | ![](https://1923141441-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MFjmFrZ8sef1J7qkr6H%2Fuploads%2FpGi0nia02jAmolvp72Jl%2Fimage.png?alt=media\&token=5fc5eac0-2285-44d1-a53a-dbb401366e91) |

{% hint style="info" %}
Since the appRules Host Service is automatically installed and ready to go, it is recommended that you use it for evaluating this sample project.  Just point your browser to the appRules URL
{% endhint %}

&#x20;

{% hint style="info" %}
The completed project is available in the appRules **Samples** project database. Click the "Open" toolbar button on the appRules home page to select the "Export SQL Tables to CSV Using Flow" project.
{% endhint %}

##

This sample project has been configured to show how to use a regular flow to export records from a SQL database to a delimited file (CSV)&#x20;

{% hint style="info" %}
Note that this approach can also be used to export records from other data sources such as Salesforce, Dynamics 365, etc.
{% endhint %}

\
For this project, you must add the BaseData module to the toolbox.\
The BaseData module is used for generically accessing data sources. The same activities can be accessed from their specific modules. For example, the SQL initialization/access activities in this sample project can be accessed from the EmbeddedDB module and the CSV initialization/access activities can be accessed from the DelimitedFile module.

<figure><img src="https://1923141441-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MFjmFrZ8sef1J7qkr6H%2Fuploads%2FtQHDTL77NsH4CIgvCMVH%2Fimage.png?alt=media&#x26;token=14969b11-6ade-4dc2-ae07-4b7f3f0b16a3" alt=""><figcaption></figcaption></figure>

**Activities:**

&#x20;

**1.      InitializeSource – Initialize SQL Source**

This activity initializes the SQL source.  Check out the properties of this activity to see how you select fields, define filters etc. for reading the data from a data source.

&#x20;

**2.      InitializeTargetFile – Initialize CSV Target File**

This activity initializes the CSV target file.  Check out the properties of this activity to see how you select fields etc. for saving data into a csv file. &#x20;

<figure><img src="https://1923141441-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MFjmFrZ8sef1J7qkr6H%2Fuploads%2FTKRJVbGFEC4jUVX5LINY%2Fimage.png?alt=media&#x26;token=151e85e8-dd13-4207-b6a1-f8998ca89b7e" alt=""><figcaption></figcaption></figure>

{% hint style="info" %}
Note that if the full path name is not specified as the file is created in the appRules Shared Files folder in the ProgramData directory
{% endhint %}

&#x20;

**3.      While Activity**

This While activity has been configured for iterating the records in the SQL source

* **MapAndSetFields**

&#x20;     This activity maps and sets the CSV record field values.

* **WriteDelimitedRecord**  &#x20;

&#x20;     This activity writes a record in the delimited file.

* **GetNextRecord**

&#x20;      This activity reads the next record from the SQL data source

&#x20;

**4.      CloseSource**

This activity closes the SQL source and releases resources.  Note:  This is also done automatically if the CloseSource activity was not included.

&#x20;

**5.      CloseTarget**

This activity closes the CSV file and releases resources.  Note:  This is also done automatically if the CloseTarget activity was not included.

&#x20;
