# MS-SQL connector as a destination

The ETL pipeline, to transfer customer data from a Langstack entity to an MS-SQL table, is created as follows.&#x20;

{% hint style="info" %}
To see step-by-step instructions of how to create an ETL pipeline, [click here](https://docs.langstack.com/welcome/get-started/learn-langstack/introduction-to-etl-pipeline).
{% endhint %}

* An ETL pipeline named “Tutorial\_entity\_to\_MSSQL” is created.&#x20;

![](https://2351945889-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FVoxOh7gdjWdmqooFdYBY%2Fuploads%2FFL0gGRpAsvSi0MClCLdP%2FTut_entitytMSSQL.png?alt=media\&token=8b45926a-fcc2-4578-bc51-36a07312e794)

* To connect to the data source, the necessary information is added as follows:&#x20;

  1. The “Entity” tab is selected.&#x20;
  2. The “Test\_MSSQL\_Entity” entity is selected from the drop-down menu.

![](https://2351945889-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FVoxOh7gdjWdmqooFdYBY%2Fuploads%2FQX2z5ZVKuJePaEJFVI0Q%2FDataSource_MSSQLEntity.png?alt=media\&token=6af30ebb-4fbc-43f1-8e14-b58f34c3e5dd)

* To connect to the data destination, the necessary information is added as follows:&#x20;

  1. The “Connector” tab is selected.&#x20;
  2. For this example, “Tutorial\_MSSQL” is selected from the drop-down menu. \
     The connector can be added by selecting a connector from the drop-down menu or a new connector can be created by clicking the \[+] button.&#x20;
  3. To go to the settings, click the “Edit the settings” arrow.

![](https://2351945889-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FVoxOh7gdjWdmqooFdYBY%2Fuploads%2F5y6BVQHngMIA2C3ZYDJC%2FDataDest_TutorialMSSQLConn.png?alt=media\&token=4909d7da-2b59-4c36-9ada-7232ec419570)

* To disallow multiple simultaneous runs of the ETL pipeline, the toggle button is left enabled for “skip execution while in progress”. \
  Enabling this toggle button defines that the execution of this ETL pipeline will be skipped when there is one already in progress.

![](https://2351945889-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FVoxOh7gdjWdmqooFdYBY%2Fuploads%2FwhZ91CIIaAqSi9n3lEfg%2FskipExecution.png?alt=media\&token=7dcf81e4-70ab-4ddc-826e-7d22526e753a)

* The default selection for ETL pipeline execution is “Immediate”.&#x20;

![](https://2351945889-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FVoxOh7gdjWdmqooFdYBY%2Fuploads%2FoPt5II2hBVZaMUekbKoI%2FImmediate.png?alt=media\&token=8983b1ed-81af-44f0-9fac-d35e991369c6)

* To align the source fields with destination fields, the settings for the reader and writer format are defined in the “Data Format” tab. \
  The “Reader” tab is selected by default.

![](https://2351945889-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FVoxOh7gdjWdmqooFdYBY%2Fuploads%2FwodgdG4LW7Sbos7Mo811%2FDataFormat_Reader_EntitySource.png?alt=media\&token=d48a227e-2760-47c1-a5a1-a3a6b88cd1e3)

* Select the fields for the Reader. For this example, the fields are added as per the image below.

![](https://2351945889-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FVoxOh7gdjWdmqooFdYBY%2Fuploads%2FBwdEdCwFAC5FyuaE6z7b%2Fentity2MSSQL_DataSource_AllFieldsAdded.png?alt=media\&token=e507de3f-7320-4249-b4be-791e87dace57)

* To update the settings for how the data should be written, select the “Writer” tab.&#x20;
  1. The writer stream is “Database Stream.”&#x20;
  2. To add the table name, click on the “Edit the settings” arrow.

![](https://2351945889-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FVoxOh7gdjWdmqooFdYBY%2Fuploads%2F5PRaXZUwnsHPUBXfGugT%2FEntity2MSSQL_WriterTab.png?alt=media\&token=8c3cc778-4dd9-461d-a956-c8a17903840a)

* To add details necessary to write the records, the settings in this section “MS-SQL format details” are defined as follows:&#x20;
  1. &#x20;The MS-SQL table name is added "TEST\_MSSQL". &#x20;
  2. On “Append” mode, the writer does not require the addition of the column names in "MSSQL format details". \
     The user needs to enter source column names separated by a comma ‘,’ such as: “customer\_id, customer\_name,customer\_email,active\_status” in this example.
  3. Click on "Accept & Collapse" to save the information.

{% hint style="info" %}
If the writer mode is Add & Update, Update, Delete or Sync, then the user needs to enter primary key/unique key column names (highlighted as number '2' in the image). This is to help identify the target record based on the primary key/unique key. &#x20;
{% endhint %}

![](https://2351945889-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FVoxOh7gdjWdmqooFdYBY%2Fuploads%2FIcUsrXjBncIkSsZYPhBC%2FEntity2MSSQL_WriterSettings.png?alt=media\&token=398afdfb-afb6-4d5b-afd5-457c1bb9e080)

* In the Field Mapping section, all the “Mapped Fields” are added and aligned.&#x20;

![](https://2351945889-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FVoxOh7gdjWdmqooFdYBY%2Fuploads%2Fdw7jLE7fSGi2EzlehvL9%2FMSSQLDestination_AllFieldMapping.png?alt=media\&token=b5cb0576-ef9f-4f72-9152-cff55b0af6c9)

* When the ETL pipeline is executed (after Save and Publish), the records will be added to the destination.&#x20;
* The records in the MS-SQL table will look as per the image below. \
  The boolean data type in Langstack is mapped to the bit data type in MS-SQL in case of the field “active\_status”. The false is converted to 0 and true is converted to 1.

!["active\_status” field in destination](https://2351945889-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FVoxOh7gdjWdmqooFdYBY%2Fuploads%2FwqC6OF0vOHUYjivbjruB%2FMSSQLDestinationTable.png?alt=media\&token=929d7216-599b-4546-af62-c2283bf23c7c)

!["active\_status” field in source](https://2351945889-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FVoxOh7gdjWdmqooFdYBY%2Fuploads%2FhAJFxKNAhQ9rfCAO37Kv%2FMSSQLDest_EntityRecords.png?alt=media\&token=c3fbd385-a5ee-402d-ba4f-b7e9507d7ef7)
