Introduction

Suppose that the "Address" column in the "Persons" table is optional. This means that if we insert a record with no value for the "Address" column, the "Address" column will be saved with a NULL value.

The NOT NULL constraint enforces a column to NOT accept NULL values.

The NOT NULL constraint enforces a field to always contain a value. This means that you cannot insert a new record, or update a record without adding a value to this field.

Checking Values in SQL

Count Null Records

  1. SELECT
  2. Ban_1,
  3. Ban_2,
  4. Ban_3,
  5. Ban_4,
  6. CASE WHEN ban_1 IS NULL THEN 1 ELSE 0 END +
  7. CASE WHEN ban_2 IS NULL THEN 1 ELSE 0 END +
  8. CASE WHEN ban_3 IS NULL THEN 1 ELSE 0 END +
  9. CASE WHEN ban_4 IS NULL THEN 1 ELSE 0 END AS TotalNULL
  10. FROM std_bnk_ans_tbl

Counting Null Records

Count Not Null Records

  1. SELECT
  2. Ban_1,
  3. Ban_2,
  4. Ban_3,
  5. CASE WHEN Ban_1 IS NOT NULL THEN 1 ELSE 0 END +
  6. CASE WHEN Ban_2 IS NOT NULL THEN 1 ELSE 0 END +
  7. CASE WHEN Ban_3 IS NOT NULL THEN 1 ELSE 0 END AS bnk_s_uid
  8. FROM std_bnk_ans_tbl

Counting Not Null Records

Count Empty Records

  1. SELECT
  2. Ban_1,
  3. Ban_2,
  4. Ban_3,
  5. Ban_4,
  6. CASE WHEN ban_1='' THEN 1 ELSE 0 END +
  7. CASE WHEN ban_2='' THEN 1 ELSE 0 END +
  8. CASE WHEN ban_3='' THEN 1 ELSE 0 END +
  9. CASE WHEN ban_4='' THEN 1 ELSE 0 END AS TotalEmpty
  10. FROM std_bnk_ans_tbl

Counting Empty Records

Thanks.