Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Subroutine help

Status
Not open for further replies.

ssmith001

Programmer
Oct 6, 2005
40
US
I have the following subroutine that 99.99% of the time will return a single value. My concern the how do I build in error trapping for the .01% in case there happens to be more than two distinct values. I want to bail.

Code:
sub what_category_do_we_process
{
  my $planner = shift;
  my ( $cur, $sql );
		
  $sql = "SELECT DISTINCT category 
  				  from promo_params 
  				 WHERE plnrcode = ? 
  				   AND processflag = 'N'";
               
  $cur = $dbh->prepare($sql);
    
  $cur->execute($planner);
	
	$cur->bind_columns(undef, \$category);

	while($cur->fetch()) 
	{	
   return $category;
	} 

}
 
Code:
sub what_category_do_we_process
{
  my $planner = shift;
  my ( $cur, $sql );
        
  $sql = "SELECT DISTINCT category
                    from promo_params
                   WHERE plnrcode = ?
                     AND processflag = 'N'";
               
  $cur = $dbh->prepare($sql);
  $cur->execute($planner);
  $cur->bind_columns(undef, \$category);

  while($cur->fetch()) {}
  return $category if ($cur->rows == 1);
  ### Error code underneath here ###
}
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top