"Mark Martin" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > Hi, > I'm running a test to see whether certain criteria in a SELECT statement > return record or not. If I get a "no rows selected" from SQL then I want to > perform a specific action . But I don't how perform the test for "no rows > selected " ? > > > $sql = qq{SELECT RECORD FROM TABLE WHERE FIELD = ? } ; > $sth = $dbh->prepare($sql) ; > $sth->execute($variable) ; > while (@fetch = $sth4->fetchrow) > { > if ("no rows selected " .................?????? ) ### Don't know how to > test this > { > #perform my tasks > } > Regards,Mark >
perhaps: if (@fetch = $sth4->fetchrow) { do { process( @fetch ) } while ( @fetch = $sth4->fetchrow ); } else { # no rows } That looks pretty clean. from perlfunc: do BLOCK Not really a function. Returns the value of the last command in the sequence of commands indicated by BLOCK. When modified by a loop modifier, executes the BLOCK once before testing the loop condition. (On other statements the loop modifiers test the conditional first.) That way you get a conditional check on if there are any rows to return at all, and if there is, the do { } while ( ... ); will process the first row fetched in the conditional before processing any more. Todd W. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>