I have the following table:
TABLE1
| ID | NAME | TYPE | COLOR |
| 1 | APPLE | FRUIT | RED |
| 2 | BANANA | FRUIT | YELLOW |
| 3 | LEMON | FRUIT | YELLOW |
| 4 | TOMATO | VEGET | RED |
| 5 | PEPPER | VEGET | RED |
| 6 | PEAR | FRUIT | GREEN |
And the input fields @TYPE and @COLOR.
If @TYPE = '*' and @COLOR = '*' then:
SELECT *
FROM TABLE1
otherwise, if @TYPE = 'VEGET' and @COLOR = '*':
SELECT *
FROM TABLE1
WHERE TYPE = 'VEGET'
if @TYPE = '*' and @COLOR = 'YELLOW':
SELECT *
FROM TABLE1
WHERE COLOR = 'YELLOW'
and the last case, if @TYPE = 'VEGET' and @COLOR = 'YELLOW':
SELECT *
FROM TABLE1
WHERE TYPE = 'VEGET'
AND COLOR = 'YELLOW'
Obviously it is not just two fields or parameters...
How can I write an efficient query to check all cases?