Using the SQL Results Macro documentation for the dotCMS Content Management System

This macro has been deprecated. See the updated SQL tool documentation.

This macro will allow you to execute a select statement on any predefined datasource.

Macro Overview:

* To use this macro, the following properties need to be first set to true in the and deployed in a configuration plugin:


**In addition, to the user creating the getSQL macro will need the Scripting User role to execute the macro.


#getSQLResults("select * from table")


  • dbConnection
    Optional: By default the macro will execute your query against the dotCMS database unless you set a dbConnection.
  • dbStartRow
    Optional: If you set dbStartRow your results will start at the given row. The dbStartRow is zero based meaning that the first row is row 0.
  • dbMaxRow
    Optional: If you set dbMaxRow your results will be limited to your maxRows. When possible your should do this with a limit in your query.

Optional Parameters:


Use this macro if you want to pull data from a database and display the results within some piece of content. If the SQL throws an error it will store the error in a variable named SQLError. See the example below for instructions on how to use this. It is only optional that you check for the error but it is recommended that you do so that your sql won"t fail silently.

Example 1: A simple example using the required fields

#set ($dbConnection = "jdbc/test1")
#set ($dbStartRow = 1)
#set ($dbMaxRow = 4)
#getSQLResults("select * from test order by id")
Custom SQL message - I Failed
#foreach($r in $results)


Example 2: Display all HTML Pages names on your site

#getSQLResults("select title from htmlpage")
#foreach($myvar in $results)