Please note : This help page is not for the latest version of Enterprise Architect. The latest help can be found here.

Custom SQL Fragments

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.

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, right-click on the Template background and select File | Document Options.

The Document Options dialog displays.




Select the Custom Query tab.




In the Template Fragment type panel, select the Custom SQL radio button.




In the main text field on the tab, type the SQL Query that is to be run on your model. This Query must return one or more columns; for example:


SELECT DocName AS TemplateName, Author AS TemplateLocation

FROM t_document

WHERE DocType = 'SSDOCSTYLE' and (IsActive = 1)

The SQL Query can also reference the ID of the Element or Package currently being processed by the document template, using the #OBJECTID# or #PACKAGEID# macros; for example:


SELECT Count(Object_Type) AS CountOfActors

FROM t_object

WHERE Object_Type = "Actor" and Package_ID = #PACKAGEID#




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 context menu 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, CountOfActors.

Click on the OK button.




Repeat steps 8 and 9 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



An Element Filter will not apply to the Custom section in a Template Fragment
You can test your SQL Query using the SQL Editor in the Model Search window

Learn more

Learning Center topics

Alt+F1 | Enterprise Architect | Reporting | RTF Template Fragments |
Create a SQL based Fragment 1
Create a SQL based Fragment 2