View previous topic :: View next topic
|
Author |
Message |
cmsmoon
New User
Joined: 17 Jun 2010 Posts: 75 Location: Chennai
|
|
|
|
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 |
|
|
chandan.inst
Active User
Joined: 03 Nov 2005 Posts: 275 Location: Mumbai
|
|
|
|
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 |
|
|
cmsmoon
New User
Joined: 17 Jun 2010 Posts: 75 Location: Chennai
|
|
|
|
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 |
|
|
chandan.inst
Active User
Joined: 03 Nov 2005 Posts: 275 Location: Mumbai
|
|
|
|
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 |
|
|
cmsmoon
New User
Joined: 17 Jun 2010 Posts: 75 Location: Chennai
|
|
|
|
I tryed like this also .but still i got +100 |
|
Back to top |
|
|
chandan.inst
Active User
Joined: 03 Nov 2005 Posts: 275 Location: Mumbai
|
|
|
|
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 |
|
|
Pandora-Box
Global Moderator
Joined: 07 Sep 2006 Posts: 1592 Location: Andromeda Galaxy
|
|
|
|
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 |
|
|
cmsmoon
New User
Joined: 17 Jun 2010 Posts: 75 Location: Chennai
|
|
|
|
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 |
|
|
Pandora-Box
Global Moderator
Joined: 07 Sep 2006 Posts: 1592 Location: Andromeda Galaxy
|
|
|
|
And did it solve the issue? |
|
Back to top |
|
|
Pandora-Box
Global Moderator
Joined: 07 Sep 2006 Posts: 1592 Location: Andromeda Galaxy
|
|
|
|
It should be IS NULL and not IS NILL |
|
Back to top |
|
|
cmsmoon
New User
Joined: 17 Jun 2010 Posts: 75 Location: Chennai
|
|
|
|
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 |
|
|
Pandora-Box
Global Moderator
Joined: 07 Sep 2006 Posts: 1592 Location: Andromeda Galaxy
|
|
|
|
Thanks for letting us know |
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19243 Location: Inside the Matrix
|
|
|
|
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 |
|
|
Pandora-Box
Global Moderator
Joined: 07 Sep 2006 Posts: 1592 Location: Andromeda Galaxy
|
|
|
|
Dick,
I believe those are very bad effects of type than copy paste |
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19243 Location: Inside the Matrix
|
|
|
|
Yup, i believe so also . . .
Bummer
d |
|
Back to top |
|
|
chandan.inst
Active User
Joined: 03 Nov 2005 Posts: 275 Location: Mumbai
|
|
|
|
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 |
|
|
Terry Heinze
JCL Moderator
Joined: 14 Jul 2008 Posts: 1248 Location: Richfield, MN, USA
|
|
|
|
As a friend of mine once said, "Knowing only one way to spell a word shows a lack of creativity." |
|
Back to top |
|
|
cmsmoon
New User
Joined: 17 Jun 2010 Posts: 75 Location: Chennai
|
|
|
|
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 |
|
|
chandan.inst
Active User
Joined: 03 Nov 2005 Posts: 275 Location: Mumbai
|
|
|
|
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 |
|
|
|