'How to search for multiple strings in a field in DB2? my query fails with '' (black/empty) values

Is there a way to build a DB2 query to search a combination of strings in a field? I am trying to do this:


select ITEM, ITEM_DESC
where instr(ITEM_DESC,>parameter1<)>0 
    AND instr(ITEM_DESC,>parameter2<)>0 
    AND instr(ITEM_DESC,>parameter3<)>0 
    AND instr(ITEM_DESC,>parameter4<)>0

UNION

select ITEM, ITEM_DESC
where instr(ITEM_DESC,>parameter5<)>0
    OR instr(ITEM_DESC,>parameter6<)>0 
    OR instr(ITEM_DESC,>parameter7<)>0 
    OR instr(ITEM_DESC,>parameter8<)>0 

The >parameters< are string inputs for the user, sometimes the user will not use all of them (dynamic list?). The query works only if all parameters have a string value, when at least one has a '' (empty), the query fails.

db2


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source