This page also provides more detailed information, explains what SQL Macros are useful for, and supplies various examples to use.
You can create SQL macros (SQM) to factor out common SQL expressions and statements into reusable, parameterized constructs that can be used in other SQL statements. SQL macros can either be scalar expressions, typically used in
HAVING clauses, to encapsulate calculations and business logic, or can be table expressions, typically used in a
FROM clause, to act as a sort of parameterized views. SQL macros increase developer productivity, simplify collaborative development, and improve code quality.
The example in the slide shows a SQL macro written as a scalar expression used in the
SELECT list of the query.
The example in the slide shows an SQL macro written as a scalar expression, used in the
SELECT list and the
WHERE clause of the query.
The example in the slide shows an SQL macro written as a table expression, then used in the
FROM list of the query.