in reply to PERL DBI MODULE

I would keep them as three separate SQL statements.

Alternatively, DBIx::PreQL allows you to construct different SQL statements from the same SQL template.

If you really want to convert them into one SQL statement, you can convert the three statements into one statement as below. Likely, the query planner will not generate a good plan for this:

my $sql= <<'SQL'; select * from mytable -- ignore or value where (? or coln1=?) and (? or coln2=?) and (? or coln3=?) SQL my $sth= $dbh->prepare( $sql ); my %parameters= (coln2 => 'Hello'); my @parameters; for my $column (qw(coln1 coln2 coln3) { if( exists $parameters{ $column }) { # Use this column value push @parameters, 0, $parameters{ $column }; } else { # Ignore this column value push @parameters, 1, undef; }; }; $sth->execute(@parameters);