# SQL Query Source

The *SQL Query Source* object enables you to retrieve data from a database using an SQL query or a stored procedure. You can specify any valid SELECT statement or a stored procedure call as a query. In addition, you can parameterize your queries dynamically, thereby allowing you to change their values at runtime.

## **Configuring the SQL Query Source**

1. Before moving on to the actual configuration, we will have to get the *SQL Query Source* object from the Toolbox onto the dataflow designer. To do so, go to *Toolbox > Sources > SQL Query Source*. In case you are unable to view the Toolbox, go to *View > Toolbox* or press Ctrl + Alt + X.

<figure><img src="https://750977703-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FqHxyVNGb7tSdIWecl6Ru%2Fuploads%2FnRERQ8lSvlIroBATW1QW%2Fimage.png?alt=media&#x26;token=e06f5a9b-aefa-43cb-8d8b-f53fc286e934" alt=""><figcaption></figcaption></figure>

2. Drag and drop the *SQL Query Source* object onto the designer.

<figure><img src="https://750977703-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FqHxyVNGb7tSdIWecl6Ru%2Fuploads%2Fp4jv6pgirsbkpaaqyUKc%2Fimage.png?alt=media&#x26;token=27be3188-40b9-4b2c-b15b-e4522c582287" alt=""><figcaption></figcaption></figure>

The source object is currently empty as we have not configured it yet.

3. To configure the *SQL Query Source* object, right-click on its header and select *Properties* from the context menu. Alternatively, you can double-click the header of the source object.

<figure><img src="https://750977703-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FqHxyVNGb7tSdIWecl6Ru%2Fuploads%2FZlunueMsOwMgyBCEeGRW%2Fimage.png?alt=media&#x26;token=f2dddc2d-b0e4-4712-ae79-59da250b5bb2" alt=""><figcaption></figcaption></figure>

A new window will pop up when you click on *Properties* in the context menu.

<figure><img src="https://750977703-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FqHxyVNGb7tSdIWecl6Ru%2Fuploads%2FOlNnP4yIRsCtfWeaevJF%2Fimage.png?alt=media&#x26;token=8e74f113-9ab7-4dbc-9a5f-d8a9370c5e68" alt=""><figcaption></figcaption></figure>

In this window, we will configure properties for the *SQL Query Source* object.

4. On this *Database Connection* window, enter information for the database you wish to connect to.

* Use the *Data Provider* drop-down list to specify which database provider you want to connect to. The required credentials will vary according to your chosen provider.

<figure><img src="https://750977703-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FqHxyVNGb7tSdIWecl6Ru%2Fuploads%2F5phyaN5lXLRE2ajtWiJz%2Fimage.png?alt=media&#x26;token=9defa7f8-33d2-4fc8-b005-6fdb9bc228a1" alt=""><figcaption></figcaption></figure>

* Provide the required credentials. Alternatively, use the *Recently Used* drop-down list to connect to a recently connected database.
* *Test Connection* to ensure that you have successfully connected to the database. A separate window will appear, showing whether your test was successful. Close this window by clicking *OK*, and then, click *Next*.

<figure><img src="https://750977703-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FqHxyVNGb7tSdIWecl6Ru%2Fuploads%2FhlJpr199eBxQIzN1PLV7%2Fimage.png?alt=media&#x26;token=77d6865f-2c60-4bb4-ad8a-20189e53ee48" alt=""><figcaption></figcaption></figure>

<figure><img src="https://750977703-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FqHxyVNGb7tSdIWecl6Ru%2Fuploads%2FgP2Isym735EbxbjsVDM4%2Fimage.png?alt=media&#x26;token=db2924a1-7669-4338-8ace-bb0805381d95" alt=""><figcaption></figcaption></figure>

5. The next window will present a blank page for you to enter your required SQL query. Here, you can enter any valid SELECT statement or stored procedure to read data from the database you connected to in the previous step.

The curly brackets located on the right side of the window indicate that the use of parameters is supported, which implies that you can replace a regular value with one that is parameterized and can be changed during runtime.

<figure><img src="https://750977703-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FqHxyVNGb7tSdIWecl6Ru%2Fuploads%2FtD2nito5XKpbQsgbV8QW%2Fimage.png?alt=media&#x26;token=adf5ae67-a0f6-4a9e-8cc2-4c198d0d3019" alt=""><figcaption></figcaption></figure>

In this example, we will be reading the *Orders* table from the *Northwind* database.

<figure><img src="https://750977703-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FqHxyVNGb7tSdIWecl6Ru%2Fuploads%2F4aCbG7hJX6DmxYmifVgB%2Fimage.png?alt=media&#x26;token=18050922-7b50-476b-8ead-89480d6447d9" alt=""><figcaption></figcaption></figure>

Once you have entered the SQL query, click *Next*.

6. The following window will allow you to check or uncheck certain options that may be utilized while processing the dataset if needed.

<figure><img src="https://750977703-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FqHxyVNGb7tSdIWecl6Ru%2Fuploads%2FDQLvYfBl9kDnFpWPZySn%2Fimage.png?alt=media&#x26;token=a3d3b107-b447-406c-9db7-53d93962459e" alt=""><figcaption></figcaption></figure>

* When checked, The *Trim Trailing Spaces* option will refine the dataset by removing extra whitespaces present after the last character in a lineup until the end of that line. This option is checked by default.
* The *Dynamic Layout* option is unchecked by default. When checked, it will automatically enable two other sub-options.
  * *Delete Field In Subsequent Objects*: When checked, this option will delete all fields that are present in subsequent objects.
  * *Add Fields In Subsequent Objects*: When checked, this option will add fields that are present in the source object to subsequent objects.

Choose your desired options and click *Next*.

7. The next window is the *Layout Builder*. Here, you can modify the layout of the table that is being read from the database. However, these modifications will only persist within Astera and will not apply to the actual database table.

<figure><img src="https://750977703-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FqHxyVNGb7tSdIWecl6Ru%2Fuploads%2FzPH2ml3RkkAh987LtXEC%2Fimage.png?alt=media&#x26;token=b653b9a5-ad86-4d73-a196-8eeb12cfc425" alt=""><figcaption></figcaption></figure>

* To delete a certain field, right-click on its serial column and select *Delete* from the context menu. In this example, we have deleted the *OrderDate* field.

<figure><img src="https://750977703-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FqHxyVNGb7tSdIWecl6Ru%2Fuploads%2FOJAPh8GCB54vdyhpu0aj%2Fimage.png?alt=media&#x26;token=66aefdb7-8104-4ebf-9ead-56950ebced7d" alt=""><figcaption></figcaption></figure>

* To change the position of a field, click its serial column and use the Move up/Move down icons located in the toolbar of the window. In this example, we have moved up the *EmployeeID* field using the Move up icon, thus shifting the *CustomerID* field to the third row. You can move other fields up or down in a similar manner, allowing you to modify the entire order of the fields present in the table.

<figure><img src="https://750977703-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FqHxyVNGb7tSdIWecl6Ru%2Fuploads%2FujJbeClX1Ia0FCTlyYUj%2Fimage.png?alt=media&#x26;token=30669609-1e6a-4ec8-add5-ac950263c2a1" alt=""><figcaption></figcaption></figure>

Once you are done customizing your layout, click *Next*.

8. In the *Config Parameters* window, you can define certain parameters for the *SQL Query Source* object.

These parameters facilitate an easier deployment of flows by excluding hardcoded values and providing a more convenient method of configuration. If left blank, they will assume the default values that were initially assigned to them.

<figure><img src="https://750977703-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FqHxyVNGb7tSdIWecl6Ru%2Fuploads%2Fl90FLYT0ZiBnSYr4qqCH%2Fimage.png?alt=media&#x26;token=86cc8e8b-a111-42ec-8709-9bac3ee02748" alt=""><figcaption></figcaption></figure>

Enter your desired values for these parameters, if any, and click *Next*.

9. Finally, a *General Options* window will appear. Here, you are provided with:
   * A text box to add *Comments*.
   * A set of *General Options* that have been disabled.

<figure><img src="https://750977703-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FqHxyVNGb7tSdIWecl6Ru%2Fuploads%2FocbybwxoSKWWW4aDYTJJ%2Fimage.png?alt=media&#x26;token=ee01a8e9-1728-4ee5-9920-62a2298f6242" alt=""><figcaption></figcaption></figure>

To conclude the configuration, click *OK*.

You have successfully configured the *SQL Query Source* object. The fields are now visible and can be mapped to other objects in the dataflow.
