Brightlane's reporting pipeline builds human-readable order summaries from a fixed template.
Write a query to return the result of applying FORMAT to the template 'Order %s placed on %s' with values '1042' and '2024-03-15'.
Output:
- A single row with one column,
order_summary, containing the formatted string.
Schema · ecommerce 5 tables
Run previews · Check grades
Write a query, then run it to see results here.
Worked solution Try it yourself first
SELECT
FORMAT('Order %s placed on %s', '1042', '2024-03-15') AS order_summary The shape
FORMAT('Order %s placed on %s', '1042', '2024-03-15') substitutes each value into its matching %s placeholder in the template, in order, and returns 'Order 1042 placed on 2024-03-15'. The template carries the fixed structure of the summary; the arguments supply the variable parts.
Clause by clause
SELECT FORMAT('Order %s placed on %s', '1042', '2024-03-15') AS order_summaryevaluates theFORMATcall and labels the resulting columnorder_summary. The first argument is the template string with two%splaceholders; the next two arguments are the values that fill them.FORMATwalks the template left to right and replaces each%swith the next positional argument, so the first%sreceives'1042'and the second receives'2024-03-15'. There is noFROMbecause everything is supplied directly in the query.
Why this and not 'Order ' || '1042' || ' placed on ' || '2024-03-15'
Both forms return the same string on this input. The FORMAT version puts the fixed structure in one place (the template literal) and the variable values in a list afterward, which is easier to read and easier to change later. The || chain interleaves literal fragments and values in alternation, which scales poorly: with five or six placeholders the chain becomes a wall of quotes and pipes. FORMAT is the right shape whenever the output structure is fixed and only the embedded values vary.
You practiced FORMAT(template, ...) with %s placeholders — the right shape when output structure is fixed and only the embedded values vary.