WHERE id = ?|;
push(@values, $form->{id});
} else {
- $query = qq|SELECT MAX(sortkey) + 1 FROM buchungsgruppen|;
+ $query = qq|SELECT COALESCE(MAX(sortkey) + 1, 1) FROM buchungsgruppen|;
my ($sortkey) = $dbh->selectrow_array($query);
$form->dberror($query) if ($dbh->err);
push(@values, $sortkey);
my $query;
if (!$form->{id}) {
- $query = qq|SELECT nextval('id'), MAX(sortkey) + 1 FROM payment_terms|;
+ $query = qq|SELECT nextval('id'), COALESCE(MAX(sortkey) + 1, 1) | .
+ qq|FROM payment_terms|;
my $sortkey;
($form->{id}, $sortkey) = selectrow_query($form, $dbh, $query);