Portal | Manuals | References | Downloads | Info | Programs | JCLs | Mainframe wiki | Quick Ref
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Profile Log in to check your private messages Log in
 
Pulling null records in a SQL

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> DB2
View previous topic :: :: View next topic  
Author Message
vinuseba

New User


Joined: 17 Feb 2014
Posts: 19
Location: India

PostPosted: Fri Apr 11, 2014 11:23 am    Post subject: Pulling null records in a SQL
Reply with quote

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
View user's profile Send private message

Pandora-Box

Moderator


Joined: 07 Sep 2006
Posts: 1543
Location: Andromeda Galaxy

PostPosted: Fri Apr 11, 2014 12:49 pm    Post subject:
Reply with quote

Is the requirement to get "only" NULL rows?
Back to top
View user's profile Send private message
vinuseba

New User


Joined: 17 Feb 2014
Posts: 19
Location: India

PostPosted: Fri Apr 11, 2014 12:52 pm    Post subject:
Reply with quote

no the requirement is to get all the rows(including nulls) expect VARA not equal to 'AB'
Back to top
View user's profile Send private message
Rohit Umarjikar

Senior Member


Joined: 21 Sep 2010
Posts: 1819
Location: NY,USA

PostPosted: Fri Apr 11, 2014 1:22 pm    Post subject:
Reply with quote

What are the values are you getting?

Also can you please show us the maked output of below query ?

Code:
Select VARA from TABLEA where VARA is null
FETCH FIRST 10 ROWS ONLY  ;


http://publib.boulder.ibm.com/infocenter/dzichelp/v2r2/index.jsp?topic=%2Fcom.ibm.db2z9.doc.sqlref%2Fsrc%2Ftpc%2Fdb2z_castspecification.htm

http://publib.boulder.ibm.com/infocenter/dzichelp/v2r2/index.jsp?topic=%2Fcom.ibm.db2z10.doc.sqlref%2Fsrc%2Ftpc%2Fdb2z_sql_createtable.htm

below are some link for references , see if that helps.
Back to top
View user's profile Send private message
vinuseba

New User


Joined: 17 Feb 2014
Posts: 19
Location: India

PostPosted: Fri Apr 11, 2014 1:43 pm    Post subject:
Reply with quote

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
View user's profile Send private message
GuyC

Senior Member


Joined: 11 Aug 2009
Posts: 1281
Location: Belgium

PostPosted: Fri Apr 11, 2014 1:46 pm    Post subject:
Reply with quote

Select VARA from TABLEA where VARA is distinct from 'AB'
Back to top
View user's profile Send private message
vinuseba

New User


Joined: 17 Feb 2014
Posts: 19
Location: India

PostPosted: Fri Apr 11, 2014 5:08 pm    Post subject:
Reply with quote

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
View user's profile Send private message
chandan.inst

Active User


Joined: 03 Nov 2005
Posts: 269
Location: Mumbai

PostPosted: Fri Apr 11, 2014 5:21 pm    Post subject:
Reply with quote

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
View user's profile Send private message
vinuseba

New User


Joined: 17 Feb 2014
Posts: 19
Location: India

PostPosted: Fri Apr 11, 2014 5:41 pm    Post subject:
Reply with quote

thank you all ...now I got it....
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> DB2 All times are GMT + 6 Hours
Page 1 of 1

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
No new posts Increment number for every group of r... srajendran2 DFSORT/ICETOOL 7 Thu Nov 09, 2017 10:31 pm
No new posts Matching and unmatched records!! Vignesh Sid SYNCSORT 3 Thu Nov 09, 2017 11:22 am
No new posts Formatting multiple records to a sing... Vignesh Sid SYNCSORT 3 Tue Nov 07, 2017 12:22 pm
No new posts Format Last Record differently from r... Learncoholic DFSORT/ICETOOL 5 Tue Oct 24, 2017 12:01 pm
No new posts sort records based on length exceeds ... maxsubrat DFSORT/ICETOOL 7 Wed Oct 04, 2017 4:48 pm

Facebook
Back to Top
 
Job Vacancies | Forum Rules | Bookmarks | Subscriptions | FAQ | Polls | Contact Us