IBM Mainframe Forum Index
 
Log In
 
IBM Mainframe Forum Index Mainframe: Search IBM Mainframe Forum: FAQ Register
 

how to handle nullable columns ( may have null or values )


IBM Mainframe Forums -> DB2
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
cmsmoon

New User


Joined: 17 Jun 2010
Posts: 75
Location: Chennai

PostPosted: Wed Jun 05, 2013 3:42 pm
Reply with quote

Hi Friends,

I have situvation to select value using nullable colums.But that nullable columns may have values .

exp

select t1.c1,t1.c2 from table1 t1 where
t1.c3=:t1.c3
and t1.c4=:t1.c4
and t1.c5=:t1.c5 ;

here C5 is a nullable columns.But some record have value ,some records have null

while using this query
what value we need to pass t.c5 ,if value is null ?
what value we need to pass t.c5 ,if the columns have value ?

Both condition we are using same query.

Note : I have moved -1 value to that null idicator value while C5 have value spaces.
Back to top
View user's profile Send private message
chandan.inst

Active User


Joined: 03 Nov 2005
Posts: 275
Location: Mumbai

PostPosted: Wed Jun 05, 2013 4:32 pm
Reply with quote

Hi,

If its null then you have to populate Null indicator column with -1 so that it will treat the column as null irrespective what value actual host variable contains...also here you need to decide when you want to treat the column as null

If it's not null then you have to populate Actual Host variable with the input value and null indicator with 0.

You need to pass Null indicator in your query which I can't see in the query provided.

What you have tried so far and what issues you are facing?

Regards,
Chandan
Back to top
View user's profile Send private message
cmsmoon

New User


Joined: 17 Jun 2010
Posts: 75
Location: Chennai

PostPosted: Wed Jun 05, 2013 5:09 pm
Reply with quote

Hi chandan,

I have handle like the below,But i got +100 while select nullable column row

if move t1.c5 = spaces
move -1 to ws-nul-c5
end-if
Back to top
View user's profile Send private message
chandan.inst

Active User


Joined: 03 Nov 2005
Posts: 275
Location: Mumbai

PostPosted: Wed Jun 05, 2013 5:23 pm
Reply with quote

As I mentioned you need to provie null indicator in query which I can't see

Your query needs to be like below

Code:
select t1.c1,t1.c2 from table1 t1 where
t1.c3=:t1.c3
and t1.c4=:t1.c4
and t1.c5=:t1.c5 :ws-nul-c5
Back to top
View user's profile Send private message
cmsmoon

New User


Joined: 17 Jun 2010
Posts: 75
Location: Chennai

PostPosted: Wed Jun 05, 2013 5:32 pm
Reply with quote

I tryed like this also .but still i got +100
Back to top
View user's profile Send private message
chandan.inst

Active User


Joined: 03 Nov 2005
Posts: 275
Location: Mumbai

PostPosted: Wed Jun 05, 2013 6:25 pm
Reply with quote

Then I would say there is no data in table which satisfies the all WHERE conditions..

Can you have some display's in program for input values and check if you are passing all things correctly to your query
Back to top
View user's profile Send private message
Pandora-Box

Global Moderator


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

PostPosted: Wed Jun 05, 2013 8:15 pm
Reply with quote

I am afraid -1 comes to picture while updating/insert of the table and not while select

And As I see you are using a host variable so how do you know if the table has null or not null values for the combination of c4 & c5 fields?

so I belive instead of Null indicator may be an additional IS NULL check needed
Back to top
View user's profile Send private message
cmsmoon

New User


Joined: 17 Jun 2010
Posts: 75
Location: Chennai

PostPosted: Wed Jun 05, 2013 8:18 pm
Reply with quote

ya.I used like below

select t1.c1,t1.c2 from table1 t1 where
t1.c3=:t1.c3
and t1.c4=:t1.c4
and ( t1.c5 is NILL
or t1.c5=:t1.c5 ) ;
Back to top
View user's profile Send private message
Pandora-Box

Global Moderator


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

PostPosted: Wed Jun 05, 2013 8:35 pm
Reply with quote

And did it solve the issue?
Back to top
View user's profile Send private message
Pandora-Box

Global Moderator


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

PostPosted: Wed Jun 05, 2013 8:47 pm
Reply with quote

It should be IS NULL and not IS NILL
Back to top
View user's profile Send private message
cmsmoon

New User


Joined: 17 Jun 2010
Posts: 75
Location: Chennai

PostPosted: Wed Jun 05, 2013 8:57 pm
Reply with quote

cmsmoon wrote:
ya.I used like below

select t1.c1,t1.c2 from table1 t1 where
t1.c3=:t1.c3
and t1.c4=:t1.c4
and ( t1.c5 is NILL
or t1.c5=:t1.c5 ) ;


The above changes has been working fine
Back to top
View user's profile Send private message
Pandora-Box

Global Moderator


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

PostPosted: Wed Jun 05, 2013 8:59 pm
Reply with quote

Thanks for letting us know
Back to top
View user's profile Send private message
dick scherrer

Moderator Emeritus


Joined: 23 Nov 2006
Posts: 19243
Location: Inside the Matrix

PostPosted: Thu Jun 06, 2013 12:34 am
Reply with quote

Hello,

Quote:
ya.I used like below

select t1.c1,t1.c2 from table1 t1 where
t1.c3=:t1.c3
and t1.c4=:t1.c4
and ( t1.c5 is NILL
or t1.c5=:t1.c5 ) ;

Quote:
The above changes has been working fine
I suspect this is not quite true . . .

There is no NILL in DB2 . . . At least not that i'm aware of.
Back to top
View user's profile Send private message
Pandora-Box

Global Moderator


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

PostPosted: Thu Jun 06, 2013 12:38 am
Reply with quote

Dick,

I believe those are very bad effects of type than copy paste
Back to top
View user's profile Send private message
dick scherrer

Moderator Emeritus


Joined: 23 Nov 2006
Posts: 19243
Location: Inside the Matrix

PostPosted: Thu Jun 06, 2013 12:45 am
Reply with quote

Yup, i believe so also . . .

Bummer icon_neutral.gif

d
Back to top
View user's profile Send private message
chandan.inst

Active User


Joined: 03 Nov 2005
Posts: 275
Location: Mumbai

PostPosted: Thu Jun 06, 2013 7:44 am
Reply with quote

cmsmoon wrote:


select t1.c1,t1.c2 from table1 t1 where
t1.c3=:t1.c3
and t1.c4=:t1.c4
and ( t1.c5 is NULL -- Corrected NILL
or t1.c5=:t1.c5 ) ;


I just suspect of possibility of returning multiple rows with above query.

if for a given combination of C3 and C4 what if there are two rows where one rows has valid value for C5 and other has Null for C5?

Learning lesson for me that Null indicator comes in picture for Insert and update I should have tested it if it works with select . I will check it today.

For Above query to avoid multiple rows can you check below. This is untested as I don't have access to mainframes right now

Code:
select t1.c1,t1.c2 from table1 t1 where
t1.c3=:t1.c3
and t1.c4=:t1.c4
and t1.c5 =  case when :t1.c5 = spaces then null else :t1.c5 end
Back to top
View user's profile Send private message
Terry Heinze

JCL Moderator


Joined: 14 Jul 2008
Posts: 1248
Location: Richfield, MN, USA

PostPosted: Thu Jun 06, 2013 8:52 am
Reply with quote

As a friend of mine once said, "Knowing only one way to spell a word shows a lack of creativity." icon_lol.gif
Back to top
View user's profile Send private message
cmsmoon

New User


Joined: 17 Jun 2010
Posts: 75
Location: Chennai

PostPosted: Thu Jun 06, 2013 10:16 am
Reply with quote

dick scherrer wrote:
Hello,

Quote:
ya.I used like below

select t1.c1,t1.c2 from table1 t1 where
t1.c3=:t1.c3
and t1.c4=:t1.c4
and ( t1.c5 is NILL
or t1.c5=:t1.c5 ) ;

Quote:
The above changes has been working fine
I suspect this is not quite true . . .

There is no NILL in DB2 . . . At least not that i'm aware of.


SORRY
it should be NULL


select t1.c1,t1.c2 from table1 t1 where
t1.c3=:t1.c3
and t1.c4=:t1.c4
and ( t1.c5 is NULL
or t1.c5=:t1.c5 ) ;
Back to top
View user's profile Send private message
chandan.inst

Active User


Joined: 03 Nov 2005
Posts: 275
Location: Mumbai

PostPosted: Thu Jun 06, 2013 3:57 pm
Reply with quote

Hi,
Apologies..

The CASE statement provided by me will not work and also Null Indicator in WHERE clause also not work

Just you need to take care of possibility of returning multiple rows with OR clause in final query

Regards,
Chandan
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic View Bookmarks
All times are GMT + 6 Hours
Forum Index -> DB2

 


Similar Topics
Topic Forum Replies
No new posts how to eliminate null indicator value... DB2 7
No new posts INCLUDE OMIT COND for Multiple values... DFSORT/ICETOOL 5
No new posts Replace Multiple Field values to Othe... DFSORT/ICETOOL 12
No new posts Remote Unload of CLOB Columns DB2 6
No new posts Increase the number of columns in the... IBM Tools 3
Search our Forums:

Back to Top