sqldb2

DB2 Conditional WHERE clause


I'm using DB2 v9

I have a stored procedure with paramaters that can potentially be passed in as empty strings. Here somer pseudocode for what I'm trying to do:

WHERE myColumn.name =
     IF param1 = '' THEN
        **disregard this param, all column values are eligible**
     ELSE
        myColumn.name = param1;

Basically just ignore the param if it is an empty string. If not, apply it as a filter in the WHERE clause. Is this possible to do in DB2?


Solution

  • SELECT ...
    FROM ...
    WHERE  param1 = '' 
       OR  myColumn.name = param1
       ;