> For the complete documentation index, see [llms.txt](https://help.sdocs.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://help.sdocs.com/sdocs/advanced-template-logic/named-query.md).

# Retrieve and Reuse Data

Use SOQL once, then reuse returned values anywhere in your S-Docs template for calculations, headers, and dynamic content.

Use this section when you need to run SOQL once and reuse the returned values across an S-Docs template.

This pattern is useful for sentences, headers, footers, calculations, and conditional output.

Use it when a full table would add noise, but the query result still drives document content.

{% hint style="info" %}
Named queries do not render rows by themselves. They store returned values so you can reference them later in the template.
{% endhint %}

### Start with the path that fits your goal

If you are new to named queries, start with the tutorial.

If you already know the output you need, use the how-to guide.

If you need exact syntax, structure, or supported patterns, use the reference.

<table data-column-title-hidden data-view="cards"><thead><tr><th>Title</th><th>Description</th><th data-card-target data-type="content-ref">Target</th></tr></thead><tbody><tr><td><strong>Getting Started with Named Queries</strong></td><td>Learn the core named query pattern, then reuse returned values across your template.</td><td><a href="/quick-start/template-building/creating-your-first-named-query-tutorial.md">Advanced Data Pulling (For Admins)</a></td></tr><tr><td><strong>Advanced Data Retrieval with Named Queries</strong></td><td>Use aggregates, filters, offsets, and grouped results to return exactly the values you need from a named query.</td><td><a href="/sdocs/advanced-template-logic/named-query/how-to-advanced-data-retrieval-with-named-queries.md">How To: Advanced Data Retrieval with Named Queries</a></td></tr><tr><td><strong>Named Queries Reference</strong></td><td>Use the reference for exact syntax, supported patterns, and advanced named query behavior.</td><td><a href="/developer-hub/template-configuration-and-styling/reference-named-query-syntax.md">Named Query Reference</a></td></tr></tbody></table>

### What you can do with retrieve and reuse data

* query a value once and reuse it across the template
* place returned values in sentences, headers, footers, and formulas
* return filtered, grouped, or aggregate results without rendering a table
* keep complex output cleaner by referencing saved query values

### Browse by topic

* [How to: Advanced Data Retrieval with Named Queries](/sdocs/advanced-template-logic/named-query/how-to-advanced-data-retrieval-with-named-queries.md)
* [Perform Calculations](/sdocs/advanced-template-logic/perform-calculations.md)
* [Use Conditional Logic](/sdocs/advanced-template-logic/conditional-logic.md)

### Related note

Use [Insert Data Tables](/sdocs/advanced-template-logic/related-lists.md) when you need repeating rows instead of reusable values inside template content.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://help.sdocs.com/sdocs/advanced-template-logic/named-query.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
