← All projects
StayBright: Loyalty Master Automation banner

StayBright: Loyalty Master Automation

An automation that rolls five loyalty Data Extensions into one Loyalty_Master record per member, ready for segmentation and personalization.

Data · Single customer viewSQLAutomation StudioData ExtensionsScenario-based build
01 · The result

What it produced

The output: Loyalty_Master, one row per member (200 members, 21 fields) with points, spend, visits, recency and tier progress.

The output: Loyalty_Master, one row per member (200 members, 21 fields) with points, spend, visits, recency and tier progress.

Automation Studio: the Loyalty_Master query ran successfully, 100% success rate, no errors.

Automation Studio: the Loyalty_Master query ran successfully, 100% success rate, no errors.

02 · How I built it

The logic, in plain English

  • Combined five sources with LEFT JOIN: members, transactions, properties, app events and tier thresholds.
  • Points, spend and visits for 6 and 12 months with SUM, CASE and DATEADD, defaulting to zero with ISNULL.
  • Points to the next tier (zero for Platinum), days since last purchase, last property visited and last app login.
  • Uses a fixed reference date so the snapshot is consistent and repeatable.
03 · Under the hood

Tier progress and 6-month activity

A short excerpt. The full code and the brief's requirements are on GitHub.

SQLLoyalty_Master.sql
/* POINTS, SPENDING AND VISITS (ZERO IF NO ACTIVITY) */
ISNULL(T6.Points_6m, 0) AS Points_6m,
ISNULL(T6.Spend_6m, 0)  AS Spend_6m,

/* POINTS NEEDED FOR NEXT TIER */
CASE
      WHEN LM.CurrentTier = 'Platinum' THEN 0
      ELSE TM.MaxPoints + 1 - LM.CurrentPoints
END AS PointsToNextTier,

/* LAST 6 MONTHS TRANSACTIONS */
LEFT JOIN (
      SELECT   T.MemberID,
               SUM(PointsEarned) AS Points_6m,
               SUM(Amount)       AS Spend_6m,
               SUM(CASE WHEN Channel = 'in_property' THEN 1 ELSE 0 END) AS Visits_6m
      FROM     [Loyalty_Transactions_StayBright] T
      WHERE    TransactionDate >= DATEADD(M, -6, '2025-10-10')
      AND      TransactionDate <= '2025-10-10'
      GROUP BY MemberID
) AS T6 ON LM.MemberID = T6.MemberID

Have a campaign, role, or idea in mind?

I'd love to hear from you.