I have a table,
id category column1 column2 column3
1 1 val1a val1b val1c
2 2 val2a val2b val2c
3 3 val3a val3b val3c
from which I need to select columns based on multiple conditions something like below.
SELECT id, category, column1, column2, column3
FROM table
WHERE id = @id
AND category IN (
select case when (@input1='Yes' AND @input2='Yes') then (select category from table where category in ('1','2'))
when (@input1='Yes' AND @input2='No') then (select category from table where category ='1')
when (@input1='No' AND @input2='Yes') then (select category from table where category ='2')
else ''
end as category)
END
Input values @input1 and @input2 are grabbed from another table, need to select and output rows with category in ('1','2') according to above condition.
What I need -
if input1=Yes and input2=Yes output rows with category in ('1','2')
if input1=Yes and input2=No output rows with category in ('1')
if input1=No and input2=Yes output rows with category in ('2')
if input1=No and input2=No output rows with category in ('')
Does case statement output multiple values? Need help.