Is there a way that I can use if statement in a select statement?
I cannot use Case statement in this one. Actually I am using iReport and I have a parameter. What I want to do is if a user does not enter a certain parameter it will select all the instances.
For example a table of person referencing to gender table, a with a parameter on where clause, query would go like:
SELECT * FROM persontable WHERE gender_id = $P{genderName}:numeric
If the parameter $P{genderName} is null or blank then it will select all. I tried this query:
SELECT * FROM persontable WHERE gender_id IN (SELECT CASE WHEN $P{genderName}
IS NULL THEB (SELECT id from genderTable
WHERE id = $P{genderName}:numeric) ELSE $P{genderName}::numeric END)
But it will return an error "More that one row is returned....." I think it is because of the CASE statement. How do I this?