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

Dynamic where clause.


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

New User


Joined: 24 Jul 2007
Posts: 18
Location: india

PostPosted: Mon Jun 14, 2010 8:16 pm
Reply with quote

Hi,

Please consider following querry.

Select *
From table T
Where A = Var1 and
B = Var2.

Now if I have a scenario where I get Value for only Var1 and in another scenario for value for only VAR2. Is there a way to accomplish all 3 scenarios in a single query? Or I have to use 3 different queries like

Select *
From table T
Where A = Var1

Select *
From table T
Where A = Var2

Select *
From table T
Where A = Var1 and
B = Var2.

Please Suggest.
Back to top
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


Joined: 20 Oct 2006
Posts: 6966
Location: porcelain throne

PostPosted: Mon Jun 14, 2010 9:40 pm
Reply with quote

why the demand for only 1 complex query?

using cobol flow control instructions
would enable an optimum query to be invoked.

otherwise, you are making the query complex
and 'slower' - more db2 resource intensive.

the extra seconds for the cobol to decide which query to use
would have a smaller impact on the machine - thus more time for others
than a complex query.
Back to top
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


Joined: 20 Oct 2006
Posts: 6966
Location: porcelain throne

PostPosted: Tue Jun 15, 2010 1:26 am
Reply with quote

Quote:
Or I have to use 3 different queries like
Select *
From table T
Where A = Var1

Select *
From table T
Where A = Var2

Select *
From table T
Where A = Var1 and
B = Var2.


it is hard to take people seriously,
when they can not even bother to be precise with their requirements.

but one example is here
Back to top
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


Joined: 20 Oct 2006
Posts: 6966
Location: porcelain throne

PostPosted: Tue Jun 15, 2010 5:40 am
Reply with quote

Or, If you are into dynamic sql, then this
Redbook - Squeezing the Most Out of Dynamic SQL with DB2 for z/OS and OS/390
is possibly what you are looking for...
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 Using Dynamic file handler in the Fil... COBOL Programming 2
No new posts JCL Dynamic System Symbols JCL & VSAM 3
No new posts Synctool-dynamic split job for varyin... JCL & VSAM 7
No new posts To search DB2 table based on Conditio... DB2 1
No new posts Dynamic file allocation using JCL JCL & VSAM 8
Search our Forums:

Back to Top