use DBI; # DBD::ODBC my $dsn = 'DBI:ODBC:Driver={SQL Server}'; my $host = '192.168.1.100,61667'; my $database = 'ABACUSDBS'; my $user = '**'; my $auth = '@@@@@@@@@@'; # Connect via DBD::ODBC using a system DSN. my $dbh = DBI->connect("$dsn;Server=$host;Database=$database", $user, $auth, {RaiseError => 1, AutoCommit => 1} ) || die " Database connection not made: $DBI::errstr"; my $dbh2 = DBI->connect("$dsn;Server=$host;Database=$database", $user, $auth, {RaiseError => 1, AutoCommit => 1} ) || die " Database connection not made: $DBI::errstr"; #Prepare a SQL statement my $sql = "SELECT TOP 1000 * FROM [ABACUSDBS].[dbo].[Bally] WHERE completed=0"; $sth = $dbh->prepare( $sql ); my $sth2 = $dbh2->prepare("UPDATE bally SET completed=1 where CarNo=?"); my $temp = 'TRUE'; #execute the statement #$dbh->begin_work; $sth->execute(); #Bind the results to the local variables $sth->bind_columns( undef, \$CarNo, \$Disc,\$Completed,\$total, \$date, \$PastDiscont, \$FullAmount ); #Retrieve values from the result set while( $sth->fetchrow_array ) { print 'test'; print "$CarNo, $Disc, $Completed, $Total, $date ,$PastDiscount, $FullAmount\n"; $sth2->execute($CarNo) } #Close the connection $sth->finish(); $dbh->disconnect(); $dbh2->disconnect();