Book a Demo
Prev Next

How to Define a Custom SQL Fragment

You can create a Template Fragment to return data from an SQL Query. You do this by defining an SQL Query in the 'Document Options' of the Template Fragment, then adding fields within the 'Custom' section of your Template Fragment that refer to the columns returned by the SQL Query. The Query is DBMS dependent and so might vary according to the DBMS you are using.

Create an SQL Query Fragment



See also


Open or create a Template Fragment in the Document Template Editor.

Document Templates Creating a Template Fragment


In the Document Template Editor:

  • Click on the Document Options icon.
    The 'Document Options' dialog displays.
  • Select the 'Custom Query' page
  • In the 'Template Fragment type' panel, select the Custom SQL radio button.
Document Options


In the main text field on the tab, type the SQL Query that is to be run on your model.

For more details see the Create a Custom SQL Query Help topic.

Create a Custom SQL Query


Click on the OK button to close the 'Document Options' dialog.


In the 'Document Template Editor', in the 'Sections' panel, select the 'Custom' checkbox to generate the 'Custom' section.

Setting Sections for Reporting


Within the 'Custom' section, right-click and select the 'Insert Custom Field' option.

A prompt displays for the name of the field to create.


In response to the prompt, type the name of the column that is being returned by your Query; for example, Note.Formatted.

Click on the OK button.


Repeat steps 6 and 7 for each column that you want to include in your report.

Add any other formatting and content you need, to the Template Fragment.


Save the Template Fragment, and add it to a normal document template.

Adding Fragments to a Document Template

Learn more