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

Case statement in where clause


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

New User


Joined: 13 Feb 2007
Posts: 5
Location: Bangalore

PostPosted: Wed Oct 17, 2007 7:11 pm
Reply with quote

Hi,
I need a help.

How to handle NULL value for host variable in a Where clause

select *
from table1
where
.
.
tdate = :host-date
.
.

When I execute the program it gives -180
I have to select data from table1 even for host-date NULL

Hence I thot of using CASE statement
if the host-date is null, then I can use NULL value in predicate as below

select *
from table1
where
.
.
case when :host-date = null or spaces
then ( tdate is NULL )
else (tdate = :host-date)
end
.
.

But I am gettting syntax error.

Please assit..
is there any simple way ?
Back to top
View user's profile Send private message
gauravgupta2808
Warnings : 1

New User


Joined: 31 May 2007
Posts: 31
Location: Chennai, India

PostPosted: Wed Oct 17, 2007 8:15 pm
Reply with quote

Try this
Code:

select *
from table1
where
.
.
.
(CASE                                       
WHEN :host-date  IS NULL THEN   
tdate IS NULL
ELSE                                         
   tdate = :host-date
                               
END)       



i am not sure if 'tdate IS NULL' works...
Back to top
View user's profile Send private message
Marso

REXX Moderator


Joined: 13 Mar 2006
Posts: 1353
Location: Israel

PostPosted: Wed Oct 17, 2007 8:39 pm
Reply with quote

Are you sure the problem is caused by a null value ?
in SQLCODE -180 I haven't seen any reference to null.
can you display the contents of SQLERRMC together with the SQLCODE ?
what is the format of the "tdate" field, and how is variable "host-date" defined ?
Back to top
View user's profile Send private message
vijigobi

New User


Joined: 13 Feb 2007
Posts: 5
Location: Bangalore

PostPosted: Tue Oct 23, 2007 8:14 pm
Reply with quote

Hi Marso,
:host-date is not actually NULL, its spaces.
I hope -180 will return if space is moved to a date field.


Hi gaurav,
'tdate IS NULL' is not working

Could anyone advise how to proceed.

I heard Case stmt can be used in where clause only for dynamic SQLs.
is that true ?
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 COBOL -Linkage Section-Case Sensitive COBOL Programming 1
No new posts To search DB2 table based on Conditio... DB2 1
No new posts Zunit Test case editor error Testing & Performance 4
No new posts JOIN STATEMENT PERFORMANCE. DFSORT/ICETOOL 12
No new posts Relate COBOL statements to EGL statement All Other Mainframe Topics 0
Search our Forums:

Back to Top