use strict; use DBI; $|=1; my (@row, $e); my$dbh = DBI->connect('DBI:ODBC:dsnname', undef, undef) or die "Couldn't connect to database: " . $DBI::errstr; $dbh->{'RaiseError'} = 1; my $sql = qq{SELECT * FROM Transaction where TransactionID=?}; my $sth = $dbh->prepare($sql); foreach my $i (968000..1029829) { $sth->execute($i); if (@row = $sth->fetchrow_array()) { print "$row[0], $row[1], $row[2]\n"; } else { print "***** No record for $i *****\n"; $e = $sth->errstr; print " Error: $e\n"; } $sth->finish(); } $dbh->disconnect(); print "\n$0 finished\n\n";