MARKETING CLOUD / SQL
SQL
Query patterns, performance pitfalls, and the SQL we actually run against Marketing Cloud Data Extensions in production.
Foundation · 2
Production note
MC SQL gotchas: what actually fires in production
Marketing Cloud SQL is a T-SQL subset, and the gaps are the part that matters. Ten gotchas we hit at scale, with the patterns we landed on after we learned the hard way.
Decision framework
Marketing Cloud SQL: Style Guide
The opinionated rules Cleon applies to every MC SQL Activity we ship — naming, formatting, commenting, patterns to prefer, anti-patterns to refuse — distilled from the gotchas and reference pages into a single discipline document.
Reference · 14
Reference
Basics — Marketing Cloud SQL fundamentals
Where MC SQL lives, what Salesforce supports, and the mental model that keeps your queries from surprising you in production.
Reference
SELECT — Marketing Cloud SQL reference
The entry clause of every SQL Query Activity in Marketing Cloud — what it is, what Salesforce officially supports, and the production patterns that survive a hand-off.
Reference
FROM — Marketing Cloud SQL reference
Where the rows come from. Data Extensions vs System Data Views, table aliases, and the production rule that protects you from views that vanish.
Reference
JOIN — Marketing Cloud SQL reference
How to combine Data Extensions in MC SQL — the four join types, the SubscriberKey type-coercion trap, anti-joins, and the staging rule that keeps performance honest.
Reference
WHERE — Marketing Cloud SQL reference
How to filter rows in MC SQL — comparison and logical operators, the IS NULL trap, NOT IN performance pitfalls, and the parentheses rule that prevents silent-precedence bugs.
Reference
LIKE — Marketing Cloud SQL reference
Pattern matching in MC SQL — wildcards, ESCAPE, case sensitivity, and the leading-wildcard performance rule that decides whether your suppression query finishes in seconds or minutes.
Reference
CASE — Marketing Cloud SQL reference
Conditional logic in MC SQL — Simple vs Searched CASE, the missing-ELSE NULL trap, type compatibility across branches, and the rule for when to stage into a lookup DE instead.
Reference
INSERT INTO — Marketing Cloud SQL reference
The only write path in MC SQL — how the INSERT INTO ... SELECT wrapper works, what each target action (Overwrite / Append / Update) actually does, and the rules that prevent silent data loss.
Reference
String functions — Marketing Cloud SQL reference
The string functions MC SQL supports — LEN, LEFT, RIGHT, SUBSTRING, LTRIM, RTRIM, LOWER, UPPER, REPLACE, CHARINDEX, CONCAT — plus the production rules for normalization, NULL handling, and the case-fold-kills-the-index trap.
Reference
Date functions — Marketing Cloud SQL reference
The date and datetime functions MC SQL supports — GETDATE, DATEADD, DATEDIFF, DATEPART, EOMONTH — plus the timezone trap, the month-math instability, and the rule for stable date filters.
Reference
Numeric functions — Marketing Cloud SQL reference
The numeric functions MC SQL supports — ABS, CEILING, FLOOR, ROUND, POWER, SQRT, SIGN, RAND — plus the integer-division trap, the precision/type rules for money columns, and why RAND can't be reused.
Reference
Conversion functions — Marketing Cloud SQL reference
Type conversion in MC SQL — CAST, CONVERT, TRY_CAST, TRY_CONVERT — plus the rule for explicit casts on every join key, why TRY_* prevents whole-Activity failures, and the date-style codes worth memorizing.
Reference
Aggregate functions — Marketing Cloud SQL reference
The aggregate functions MC SQL supports — COUNT, SUM, AVG, MIN, MAX — plus the COUNT(*) vs COUNT(col) distinction, the SUM-returns-NULL-on-empty trap, and the MAX-per-group dedup pattern that replaces window functions in MC.
Reference
Null functions — Marketing Cloud SQL reference
Handling NULL in MC SQL — ISNULL, COALESCE, NULLIF, plus the rule for picking COALESCE over ISNULL, the NULLIF division-by-zero idiom, and the difference between ISNULL the function and IS NULL the operator.
How-to · 3
How-to
Debugging email sends with SQL
When a Send went out but the numbers don't match expectations, the diagnostic flow is the same every time — audience funnel, suppression check, _Sent reconciliation, bounce/error breakdown. Five queries that find the bug fast.
How-to
Debugging value length with SQL
Silent string truncation is the bug that finds you weeks later — emails merging into the wrong subscriber, codes losing their suffix, names cut at character N. Three queries to find truncated values, audit destination DE column widths, and prevent the next one.
How-to
Debugging All Contacts with SQL
Reconciling Marketing Cloud's All Contacts view against your Data Extensions — why a subscriber appears in one and not the other, status mismatches across channels, deletion-in-progress states, and the queries that surface each.