# Custom Queries

This sample project demonstrates how to define and use a custom query to read data records.

In the sample, instead of **configuring** selection options for the source, the appRules Custom Query Editor is used to define a simple query.&#x20;

Feel free to experiment with your own queries.

{% hint style="info" %}
The appRules Custom Query Editor supports SQL query access for all data sources.  This includes not only relational databases, but also SaaS platforms such as Salesforce, Dynamics365, Snowflake, etc.&#x20;
{% endhint %}

<figure><img src="https://1923141441-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MFjmFrZ8sef1J7qkr6H%2Fuploads%2FlDzHf5A8Bl1SMgID4bX7%2Fimage.png?alt=media&#x26;token=e7f4b260-b960-4066-882b-d8fbd00d0c15" alt=""><figcaption></figcaption></figure>

<figure><img src="https://1923141441-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MFjmFrZ8sef1J7qkr6H%2Fuploads%2FAm5gUKqsXes7eKqDCjQR%2Fimage.png?alt=media&#x26;token=b93ab1f4-720e-4983-86aa-01b2901647e4" alt=""><figcaption></figcaption></figure>

**Points of interest:**

* **1 - InitializeSource Activity**

Select CustomQuery as the QueryType instead of Configuration.  Click the Add/Edit Query property to define the custom query:

<figure><img src="https://1923141441-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MFjmFrZ8sef1J7qkr6H%2Fuploads%2FQjFdYWxNNriCspoyuXvA%2Fimage.png?alt=media&#x26;token=a2485daa-26f4-4515-bd8c-84d186087b52" alt=""><figcaption></figcaption></figure>

* **2 - While Activity**

The While activity is used to loop through and view the resulting records. It has been configured with a condition to to end after reading the last record from the dataset.

* **3 - ViewRuntimeRecords Activity**

This activity has been configured to display the current record. In an actual project, the values can be used for loading additional data, calculations, etc.

* **4 - GetNextRecord Activity**

This activity gets the next record from the resulting dataset.
