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

Want to declare 3 cursors for 3 conditions


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

Active Member


Joined: 13 Feb 2004
Posts: 551
Location: Bangalore

PostPosted: Tue Nov 28, 2006 1:46 pm
Reply with quote

i have a cursor declared as
declare c1 cursor for
select name,empno,empdept
from table
where
name = :ws-name
and empno =:ws-empno
and dept = :ws-dept

now depending on an input condition the where clause will change ...it can use 3 keys ....if 3 keys are thr in input or else 1st and 3rd or 2 nd and 3rd

i dont want to declare 3 cursors for 3 conditions ....
if only name and empno is thr in input and thr is no value for dept the where clause shud have only name and empno ...

is thr any way out of this ...
if i can use dynamic sql how do i declare it .....open and fetch ....
pls help
Back to top
View user's profile Send private message
UmeySan

Active Member


Joined: 22 Aug 2006
Posts: 771
Location: Germany

PostPosted: Tue Nov 28, 2006 5:41 pm
Reply with quote

Hi !

For a quick and easy entry in DynamicSQL please look at www.craigsmullins.com/dbu_1004.htm.

But remenber that dynamic sql is increasing performance !!!

In a lot of companies with the need of high performance applications it's forbidden to use dynamic sql.

So just make it easy. Define three cursors and a few minutes later, your work is done.

Regards, UmeySan
Back to top
View user's profile Send private message
ashimer

Active Member


Joined: 13 Feb 2004
Posts: 551
Location: Bangalore

PostPosted: Thu Nov 30, 2006 11:29 am
Reply with quote

thanks umey for ur response ..... but here the above cursor was just an example .....actually the where clause contains 6 keys ..and in total i shud declare 18 cursors which is goin to give a huge bind ....
neways i figured out a way for this ...
u can declare the cursor as below ...
declare c1 cursor for
select name,empno,empdept
from table
where
( name = :ws-name or name = ' ')
and ( empno =:ws-empno or empno = ' ' )
and ( dept = :ws-dept or dept = ' ')

this worked fine .........
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 load to DB2 with column level ... DB2 6
No new posts Db2 SQL - how to switch among differe... DB2 18
No new posts To search DB2 table based on Conditio... DB2 1
No new posts Positioned Deletes/Updates using curs... DB2 3
This topic is locked: you cannot edit posts or make replies. SUM based on two conditions using SYN... SYNCSORT 7
Search our Forums:

Back to Top