in reply to SQl logic inPerl

Maybe you want just

my $sql = <<SQL; select name, year from mytable where acc = 12345 and (year =? or year =?+1) SQL; my $sth_year = $dbh->prepare($sql); $sth_year->execute( $year ); my $results = $sth_year->fetchall_arrayref(); ...

Replies are listed 'Best First'.
Re^2: SQl logic inPerl
by Anonymous Monk on Jul 14, 2010 at 18:24 UTC
    That looks good on Perl but it doesn't fix the issue.

      So, what is the issue? Is the issue that you get two lines? Maybe you want to get the first line, when you ORDER BY some criterion? You haven't shown any example output and what result you prefer over what other result, so it's kinda hard to guess what you might mean.

        I can try to explain the possibilities; if I have two records into this database table one from 2009 and the other from 2010, the query in question will bring both and not just one of the records, like it is the intention on the SQL query I am trying to do. I just need to get 2009 if it is there, if not then go get me 2010 record.