View previous topic :: View next topic
|
Author |
Message |
vinuseba
New User
Joined: 17 Feb 2014 Posts: 19 Location: India
|
|
|
|
hi ,
The field VARA is declared as below in the DDL of TABLEA.
VARA CHARACTER(2) FOR MIXED DATA
WITH DEFAULT NULL
While using VARA in in an SQL do i need to give a condition specificaly in the where clause as "VARA is NULL" to get the null values in the output?
Because the result of below two quries is different.
QUERY-1
Select count(*) from TABLEA where VARA <> 'AB' ;
QUERY-2
Select count(*) from TABLEA where VARA <> 'AB' or VARA is null ; |
|
Back to top |
|
|
Pandora-Box
Global Moderator
Joined: 07 Sep 2006 Posts: 1592 Location: Andromeda Galaxy
|
|
|
|
Is the requirement to get "only" NULL rows? |
|
Back to top |
|
|
vinuseba
New User
Joined: 17 Feb 2014 Posts: 19 Location: India
|
|
|
|
no the requirement is to get all the rows(including nulls) expect VARA not equal to 'AB' |
|
Back to top |
|
|
Rohit Umarjikar
Global Moderator
Joined: 21 Sep 2010 Posts: 3053 Location: NYC,USA
|
|
Back to top |
|
|
vinuseba
New User
Joined: 17 Feb 2014 Posts: 19 Location: India
|
|
|
|
Please find the output of the query below.
Query
Select VARA from TABLEA where VARA is null
FETCH FIRST 10 ROWS ONLY ;
Result:
VARA
-----
-
-
-
-
-
-
-
-
-
- |
|
Back to top |
|
|
GuyC
Senior Member
Joined: 11 Aug 2009 Posts: 1281 Location: Belgium
|
|
|
|
Select VARA from TABLEA where VARA is distinct from 'AB' |
|
Back to top |
|
|
vinuseba
New User
Joined: 17 Feb 2014 Posts: 19 Location: India
|
|
|
|
Select VARA from TABLEA where VARA is distinct from 'AB'
is meeting our requirement ; but my concern is if we donot give "VARA is NULL" condition in the where condition wont it pull the null records? |
|
Back to top |
|
|
chandan.inst
Active User
Joined: 03 Nov 2005 Posts: 275 Location: Mumbai
|
|
|
|
It won't because you can not compare Null with any value.
So with
Code: |
Select count(*) from TABLEA where VARA <> 'AB' ; |
Db2 cant decide Null is not equal AB.
Search more in DB2 manuals on Null values you will get more details
Regards,
Chandan |
|
Back to top |
|
|
vinuseba
New User
Joined: 17 Feb 2014 Posts: 19 Location: India
|
|
|
|
thank you all ...now I got it.... |
|
Back to top |
|
|
|