my $sth_history = $dbh->prepare("Select COUNT(auftr_num) AS Total from ticket_system WHERE auftr_num = '$recordset[2]'"); $sth_history->execute || die "Select from ticket_system fehlgeschlagen: DBI::errstr\n"; my $total = $sth_history->fetchrow_array(); $liste .= "$total"; if ($total > 0){ my $history_number = $dbh->prepare("Select MAX(history_num) from ticket_system WHERE auftr_num = '$recordset[2]'"); $history_number->execute || die "2.Select from ticket_system fehlgeschlagen: DBI::errstr\n"; my $last_history = $history_number->fetchrow_array(); $last_history++; $liste .= "$last_history"; } else { $liste .= "$total"; $last_history = 1; }