For the complete documentation index, see llms.txt. This page is also available as Markdown.

Use dynamic SQL inputs

Reuse a query with different values by defining inputs rather than editing the SQL each time.

Before you start

Connect a SQL resource and open the SQL Query Builder. This example assumes an Orders table containing id, customer_id, and total. Use the table and column identifiers shown in your resource.

Define and use an input

  1. Add a numeric input named customer_id in the query's inputs.

  2. Enter a test value, such as 1.

  3. Insert the input into the query:

SELECT id, customer_id, total
FROM Orders
WHERE customer_id = {{params.customer_id}};
  1. Run the query using the test control and inspect the returned rows.

  2. Change the test input to 2 and run it again.

  3. Save the query after verifying both results.

Jet Tables example

This separate template-data example defines a required numeric customer_id input. The standalone customer lookup uses the actual table identifier shown by Jet Tables and returns customer 5, Ada Gazey.

Numeric customer_id input, SQL lookup, and result for customer 5
Use the table identifiers in your own resource; the template customer in this example has ID 5.

Verify

Every returned row should have the requested customer ID. An empty result can be valid if that customer has no orders.

Succeeded SQL request with customer_id 99999 and no returned records
The related Tickets–Customers join succeeds but returns no rows for customer_id 99999. Check the input and matching data before treating an empty result as an error.

This empty-result screenshot uses the ticket/customer join example, rather than the standalone lookup above.

Bind the saved input to an appropriate app value when using the query in a component. A filter is not a substitute for permissions.

For editor controls, see SQL Query Builder. For existing queries using older input syntax, see Write and test a SQL query.

Was this helpful?