a true IF…THEN statement would be useful here, but I am not aware of one. I have the user passing in 2 parameters (cfk_in and senr_in) into my query, and based on whether the param is Y or N, I will change my query, here is my current query:
select a.course_id, a.topic_code
from course_sections a,
statuses b
where a.course_id = b.course_id
and term = upper('2010FALL')
and status = 'P' and pos = 1
So this is pretty simple and would give me all sections and topic codes for a particular term. If the user passes in both params as ‘N’, I would like to just keep it at the above query. If the user passes in cfk_in = ‘Y’ and senr_in = ‘N’ then I would like to add “and a.topic_code = ‘CFK%'”, and like wise if the user passes in cfk_in = ‘N’ and senr_in = ‘Y’, I would like to add “and a.topic_code = ‘SENR'”. I am not allowing them to pass both in as ‘Y’.
Is there a way to do this in one query? Thanks for the help.
It’s quite simple:
This will also disallow passing both parameters as
'Y', as that would return no results. Ifcfk_inandsenr_inaren’t actual fields in your table, then mark them as bind variables:Or with Java:
… binding
cfk_inat indexes 1, 3, 5, andsenr_inat indexes 2, 4, 6N.B: I think you meant to filter
a.topic_code like 'CFK%', nota.topic_code = 'CFK%'