---
title: "How to use SQL macro in a Confluence user macro"
canonical: "https://support.appfire.com/space/SUPPORT/89142208/How%20to%20use%20SQL%20macro%20in%20a%20Confluence%20user%20macro"
format: markdown
---
<span style="color: #333333">This article explains how to use SQL macro of the </span>*<span style="color: #333333">SQL for Confluence</span>*<span style="color: #333333"> app in a user macro section of Confluence. This article presents inserting a simple SQL statement in the user macro.</span>

## <span style="color: #333333">Instructions</span>

1. <span style="color: #333333">Prerequisites: Make sure the database connection is successful using the </span>*<span style="color: #333333">SQL for Confluence</span>*<span style="color: #333333"> app.</span>
  1. <span style="color: #333333">Log in to your Confluence instance as an administrator.</span>
  2. <span style="color: #333333">Navigate to </span>> Macro (inline-external-image)

***<span style="color: #333333">(</span>******<span style="color: #333333">Cogwheel)</span>******<span style="color: #333333"> > Manage apps</span>***<span style="color: #333333">.</span>
  3. <span style="color: #333333">Select the </span>***<span style="color: #333333">SQL app > View and modify data source profiles</span>***<span style="color: #333333"> f</span><span style="color: #333333">rom the left sidebar </span><span style="color: #333333">and ensure that connection to the database is successful.</span>  
> Macro (inline-media-image)
2. <span style="color: #333333">You can perform this action using two methods.</span>

<details>
<summary>Method 1:</summary>

1. <span style="color: #333333">Insert </span>***<span style="color: #333333">SQL</span>****<span style="color: #333333"> macro.</span>*  
> Macro (inline-external-image)
2. <span style="color: #333333">Enter the SQL statement as required. In this example, a query is used to retrieve data from the </span>*<span style="color: #333333">persons </span>*<span style="color: #333333">table.</span>  
> Macro (inline-external-image)

  
> Macro (inline-external-image)
3. <span style="color: #333333">Copy the storage of the page:</span>  
> Macro (inline-external-image)

  
> Macro (inline-external-image)
4. <span style="color: #333333">Navigate to </span>***<span style="color: #333333">Settings > General Configuration > User Macros</span>***<span style="color: #333333"> and click the </span>*<span style="color: #333333">Create a User Macro</span>*<span style="color: #333333"> link to create a new user macro.</span>  
> Macro (inline-external-image)
5. <span style="color: #333333">Fill in the required parameters and </span>*<span style="color: #333333">Categories</span>*<span style="color: #333333"> as per the requirement.</span>
6. <span style="color: #333333">Insert the storage format in the </span>*<span style="color: #333333">Template </span>*<span style="color: #333333">and click </span>**<span style="color: #333333">Save</span>**<span style="color: #333333">.</span>  
> Macro (inline-external-image)
7. <span style="color: #333333">Now use the user macro in the confluence page.</span>  
  
> Macro (inline-external-image)

**<span style="color: #333333">Output:</span>**  
> Macro (inline-external-image)
</details>

<details>
<summary>Method 2:</summary>

1. <span style="color: #333333">Navigate to </span>***<span style="color: #333333">Settings > General Configuration > User Macros</span>***<span style="color: #333333"> and click the </span>*<span style="color: #333333">Create a User Macro</span>*<span style="color: #333333"> link to create a new user macro.</span>  
> Macro (inline-external-image)
2. <span style="color: #333333">Fill in the required parameters and </span>*<span style="color: #333333">Categories</span>*<span style="color: #333333"> as per the requirement.</span>
3. <span style="color: #333333">Enter the SQL query including the output format i</span><span style="color: #333333">n the </span>*<span style="color: #333333">Template </span>*<span style="color: #333333">section, enter</span><span style="color: #333333"> data source details, and click </span>**<span style="color: #333333">Save</span>**<span style="color: #333333">.</span>  
> Macro (inline-media-image)

  
> Macro (inline-media-image)
4. <span style="color: #333333">Now use the user macro in the confluence page.</span>  
> Macro (inline-media-image)

**<span style="color: #333333">Output:</span>**

![image](media://a3c86cd8-4f66-4025-95b5-403d972c344c)
</details>