SQL templates

Two types of SQL templates are available in enKod – for segmentation and for dynamic content. Segmentation templates allow for the deepest possible filtering of the database, using any customer data that can be stored in tables. SQL for DK is typically used to substitute required products or other personal information into emails. enKod supports PostgreSQL syntax. You can learn more about query syntax and SQL features in the freely available documentation.

SQL for segmentation

Templates of this type always return a list of contacts in the response. SQL for segmentation can also be used in segment conditions.

To create a SQL template for segmentation go to the tab DataSQL templatesCreateSQL for segments

Enter the SQL template name, description (if necessary) and the query body itself.

You can see the list of contacts matching the conditions after clicking the “Run Query” button.

Parameters in templates are needed to unify any standard queries and allow you to change the body of the query directly from the segment creation.

For example, if you are organising events, for each event you have a segment of participants selected in a certain way using a template. The general syntax of the template is the same for each event, only the event identifier changes. To avoid creating a separate template for each segment, you can set an empty parameter in the template, which can be filled with the corresponding identifier value directly from editing the segment.

The table with participants will look like this

Create a template for segmentation with the parameter

You can use a template in a segment as follows

For the SQL template for segmentation to work correctly, the column type in the TD must be “email”, not text or other. Only one column must be selected in the template.

SQL for dynamic content

Templates of this type return fields from a table that match the specified conditions. They are used in emails for personalisation and trigger mechanics.

To create an SQL template for a DK go to the tab DataSQL templatesCreateSQL for dynamic content

Enter the name of the SQL template, a description (if necessary) and the query body itself.

You can see the list of matching fields after clicking the “Run Query” button.

You can also use parameters in the templates for DCs.

Viewing the SQL template when creating a segment

For convenience, you can view the SQL template body itself in the segment. To do this, click on the corresponding button after selecting the template. You cannot edit a query from the segment.

Last modified: 2023.12.13 10:33 by Anastasia Aniskova