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.
Count Null Records
- SELECT
- Ban_1,
- Ban_2,
- Ban_3,
- Ban_4,
- CASE WHEN ban_1 IS NULL THEN 1 ELSE 0 END +
- CASE WHEN ban_2 IS NULL THEN 1 ELSE 0 END +
- CASE WHEN ban_3 IS NULL THEN 1 ELSE 0 END +
- CASE WHEN ban_4 IS NULL THEN 1 ELSE 0 END AS TotalNULL
- FROM std_bnk_ans_tbl
Count Not Null Records
- SELECT
- Ban_1,
- Ban_2,
- Ban_3,
- CASE WHEN Ban_1 IS NOT NULL THEN 1 ELSE 0 END +
- CASE WHEN Ban_2 IS NOT NULL THEN 1 ELSE 0 END +
- CASE WHEN Ban_3 IS NOT NULL THEN 1 ELSE 0 END AS bnk_s_uid
- FROM std_bnk_ans_tbl
Count Empty Records
- SELECT
- Ban_1,
- Ban_2,
- Ban_3,
- Ban_4,
- CASE WHEN ban_1='' THEN 1 ELSE 0 END +
- CASE WHEN ban_2='' THEN 1 ELSE 0 END +
- CASE WHEN ban_3='' THEN 1 ELSE 0 END +
- CASE WHEN ban_4='' THEN 1 ELSE 0 END AS TotalEmpty
- FROM std_bnk_ans_tbl
Thanks.