#!/usr/bin/perl -w use strict; use Win32::ODBC; my $DSN = "DSN=DATABASE1;UID=sa;PWD=password;"; my $connection = new Win32::ODBC("$DSN"); if (!$connection){die "Could not open connection to DSN because of [$!]";} my $SQL = "SELECT Field1, Field2 FROM table1"; if ($connection->Sql($SQL)) { print "SQL failed.\n"; print "Error: " . $connection->Error() . "\n"; print $connection->Error() . "\n"; $connection->Close(); die;} #Report header. print "Field 1" . "\t\t\t" . "Field 2" . "\n"; while ($connection->FetchRow()) { my %dataRow =$connection->DataHash(); print $dataRow{field1} . "\t\t" . $dataRow{field2} . "\n";} $connection->Close(); my $DSN2 = "DSN=DATABASE2;UID=sa;PWD=password;"; my $connection2 = new Win32::ODBC("$DSN"); if (!$connection2){die "Could not open connection to DSN because of [$!]";} my $SQL2 = "SELECT * FROM TABLE2"; if ($connection2->Sql($SQL2)) { print "SQL failed.\n"; print "Error: " . $connection->Error() . "\n"; print $connection->Error() . "\n"; $connection->Close(); die;} while ($connection2->FetchRow()) { my %dataRow2 =$connection2->DataHash(); print $dataRow2{field1} . "\t\t" . $dataRow2{field2} . "\n";} $connection->Close();