SQL Flow Field Guide

Filter rows with NULL

Write a filter that treats missing values as a separate case.

What you are trying to do

A queue report should show ready items and items whose state has not been set.

Work through it

  1. Read the synthetic state values.
  2. Check how the predicate handles NULL and the excluded state.
  3. Change one test value and predict whether its row remains.

Check your work

The result includes ready and unset rows and excludes held rows.

Practice SQL

Open in SQL Flow
SELECT ItemId, State FROM (VALUES (1, CAST(N'Ready' AS nvarchar(10))), (2, N'Hold'), (3, NULL)) AS QueueItem(ItemId, State) WHERE State IS NULL OR State <> N'Hold';

Commands in this lesson

Next lesson Order a short result