I am trying to run a select query against a mySQL database using the following code:
my $filter = "('Y' || 'N')";
my $sth = $dbh->prepare(q{SELECT name FROM catagories WHERE catagories
+.workrelated = ? ORDER BY name});
$sth->execute($filter);
However, this returns no data. Even if I omit the variable and do this:
my $sth = $dbh->prepare(q{SELECT name FROM catagories WHERE catagories
+.workrelated = ? ORDER BY name});
$sth->execute("('Y' || 'N')");
I still get nothing.
If I put the information in $filter directly into the prepare statement like this:
my $sth = $dbh->prepare(q{SELECT name FROM catagories WHERE catagories
+.workrelated = ('Y' || 'N') ORDER BY name});
$sth->execute();
Then the output is correct. What am I doing that confuses the DBI?