MVSFORUMS.com Forum Index MVSFORUMS.com
A Community of and for MVS Professionals
 
 FAQFAQ   SearchSearch   Quick Manuals   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Dynamic where clause

 
Post new topic   Reply to topic   printer-friendly view    MVSFORUMS.com Forum Index -> Database
View previous topic :: View next topic  
Author Message
Jamylady
Beginner


Joined: 04 Nov 2004
Posts: 68
Topics: 22

PostPosted: Wed Apr 06, 2011 1:25 pm    Post subject: Dynamic where clause Reply with quote

Hello,
I need to design a query to rerieve data from two tables based on conditions on various columns. But the values supplied for these columns dpends on user inputs. so if the user inputs values only for 3 columns, my SQL should make use of those values and run the query
For example, if I have only two inputs (year and ssn), then my SQL should be something like
Code:
Select TAX_YR, SSN, CONTRACT_NO, AMT_1, AMT_2
FROM TAX_MAIN,
         TAX_CONTRACT
WHERE
         TAX_YR = :TAX-YR
AND  SSN = :SSN

But if the user provides taxable_income = 'Y' then my SQL should be
Code:
Select TAX_YR, SSN, CONTRACT_NO, AMT_1, AMT_2
FROM TAX_MAIN,
         TAX_CONTRACT
WHERE
         TAX_YR = :TAX-YR
AND  SSN = :SSN
AND TAXABLE_INC = 'Y'


There is a maximum of eight columns where users can input data.
Is there any way I can write a sigle SQL to handle this?
How we can do this even if I need to use a stored procedure?

Thanks
JA
Back to top
View user's profile Send private message
Jamylady
Beginner


Joined: 04 Nov 2004
Posts: 68
Topics: 22

PostPosted: Wed Apr 06, 2011 1:27 pm    Post subject: Reply with quote

Sorry, the second SQL should have been as given below
Code:

Select TAX_YR, SSN, CONTRACT_NO, AMT_1, AMT_2
FROM TAX_MAIN,
         TAX_CONTRACT
WHERE
         TAX_YR = :TAX-YR
AND  SSN = :SSN
AND TAXABLE_INC = :TAXABLE-INC
Back to top
View user's profile Send private message
kolusu
Site Admin
Site Admin


Joined: 26 Nov 2002
Posts: 12378
Topics: 75
Location: San Jose

PostPosted: Wed Apr 06, 2011 2:56 pm    Post subject: Reply with quote

Jamylady,

Read about Coding dynamic SQL in application programs

Kolusu
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic   printer-friendly view    MVSFORUMS.com Forum Index -> Database All times are GMT - 5 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


MVSFORUMS
Powered by phpBB © 2001, 2005 phpBB Group