Posted: Wed Apr 06, 2011 1:25 pm Post subject: Dynamic where clause
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?
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