Technical Article

Validating null values in a column without using ISNULL or NVL.

,

The SQL code compares the count(*) and count(id) and if the difference is more than 0 it means null exist.

create table test
(id int)

INSERT INTO TEST VALUES (1)
INSERT INTO TEST VALUES (2)
INSERT INTO TEST VALUES (null)

SELECT COUNT(*) AS A,COUNT(ID) as B,A - B AS TEST,
CASE WHEN TEST >0 THEN 'NULL EXIST' ELSE 'NULL DOES NOT EXIST' END
FROM TEST

ABTESTCASE
321NULL EXIST

Rate

★ ★ ★ ★ ★ ★ ★ ★ ★ ★

(9)

You rated this post out of 5. Change rating

Share

Share

Rate

★ ★ ★ ★ ★ ★ ★ ★ ★ ★

(9)

You rated this post out of 5. Change rating