# Write a custom SQL query in a report

> Add one SQL query to a report to generate new fields, then join those fields to the rest of the report.

This guide explains how to add a custom SQL query to a report and edit the query later.

You can use SQL in a report to generate new fields and join those fields with other data in the report.

Keep the following limitations in mind:

-   You can add only one SQL query to each report.
-   The query is saved only within the report where you created it.
-   You cannot reuse the query in other reports.
-   The query is not saved as a custom data object in Rippling.

## Add a SQL query to a report

1.  With your report open for editing, hover over _Custom SQL_ in the _Available data_ panel and click the **\[+\]** icon.
2.  The _Edit SQL_ window opens. Write your SQL query. Refer to the [SQL Reference Glossary](https://developer.rippling.com/documentation/rippling-platform/transformations/sql-reference-glossary) for information about what’s supported.
3.  To test your query, click **Run** in the top right corner and review the output in the window below the editor.
4.  When your query is complete, click **Validate and apply** in the top right corner.
5.  Wait while the query is validated. If the validation fails, you’ll see an error message to let you know why. Go back to the prior screen or close the modal and make any necessary adjustments to your query.
6.  When the query passes validation, click **Continue**.

The fields that were created as the output of your query are added to the _Selected fields_ area.

Just like when you add data to a report from any other dataset, Rippling automatically joins the fields you created with the other data in the report. You can adjust the joins as needed by clicking the **pencil** icon next to _Joins_ at the bottom of the _Available data_ panel. For more information, see [Joins in reports](https://developer.rippling.com/documentation/rippling-platform/reports/joins).

## Edit the SQL query in a report

If you want to change the SQL query, there are two ways to open it for editing:

-   Hover over _Custom SQL_ in the _Available data_ panel and click the **pencil** icon.
-   In the _Filters & controls_ panel at the top of the page, click **Edit SQL**.

The SQL editor window opens. Make your changes, then follow the steps above to validate and save your query.

## See also

-   [Get started with reports](https://developer.rippling.com/documentation/rippling-platform/reports/getting-started)
-   [Joins in reports](https://developer.rippling.com/documentation/rippling-platform/reports/joins)
-   [Filters and time frames in reports](https://developer.rippling.com/documentation/rippling-platform/reports/filters)
-   [Charts and grouping in reports](https://developer.rippling.com/documentation/rippling-platform/reports/visualization)
-   [SQL Reference Glossary](https://developer.rippling.com/documentation/rippling-platform/transformations/sql-reference-glossary)

Source: https://developer.rippling.com/documentation/rippling-platform/reports/custom-sql

> For the complete documentation index, see [llms.txt](https://developer.rippling.com/llms.txt). Public pages have a Markdown version at the same URL with .md added.
