SQL chapters

Chapter 4 of 17

Expressions and query parameters

Try this in our SQLite Compiler →

The idea

SQLite SQL has no DECLARE @name statement. Use literal expressions in practice scripts and bound parameters in application code. A parameter is supplied through a database API, not by string concatenation. A common table expression can name a small input relation for a standalone example.

Worked example

WITH settings(minimum_score) AS (VALUES (70))
SELECT minimum_score, minimum_score + 10 AS next_target FROM settings;

What to check

This query returns 70 and 80. settings exists for this statement only. It is not a session variable or a stored table.

Practice task

Change the one input value to 60 and predict both result columns before running the query.

Check your understanding

Explain the result in your own words before changing the example. Change one thing at a time, compare the result with your prediction, and keep the version that demonstrates the concept clearly.

Try it yourself

Output
Run your project to see output here.
Ctrl/Cmd+Enter runs · Ctrl/Cmd+S downloads the project · Local auto-save is always on