SamueD2 has asked for the wisdom of the Perl Monks concerning the following question:
use strict; use warnings; use DBI; #use Win32::ODBC; use DBD::ODBC; # Global Variables my @statement; # Array of sql statements that will be used for Sql my @data; # Array of table rows read from Sybase my @message; # Array of error messages used for debugging Sql # SQL Connection my $dbh = DBI->connect( "dbi:ODBC:RETDEV_SQL", "sa", "henry", {RaiseError => 1, PrintError => 1, AutoCommit => 1} ) or die "Unable to connect: ";#. $DBI::errstr . "\n"; # Sybase Connection my $dbh2 = DBI->connect( "dbi:ODBC:BPSA", "vornoi", "vornoi14", {RaiseError => 1, PrintError => 1, AutoCommit => 1} ) or die "Unable to connect: ";#. $DBI::errstr . "\n"; #Create the sql statement for Sybase and execute it $sth = $dbh2->prepare("SELECT (dbo.tbookkeeping_trans.branch_cd + dbo. +tbookkeeping_trans.account_cd)As AccountNo, 'TRI'as TransferFlag,'NCT' as TransferType, 'C' as RejectType, dbo.tbo +okkeeping_trans.security_adp_nbr as AdpNumber, dbo.tbookkeeping_trans.share_trans_qty as Shares,dbo.tbookkeeping_tra +ns.processing_dt FROM dbo.tbookkeeping_trans WHERE (dbo.tbookkeeping_trans.client_nbr='0030' AND dbo.tbookkeeping_t +rans.entry_cd IN ('JNL', 'JRL', 'REC') AND dbo.tbookkeeping_trans.branch_cd >'248') ORDER BY 1"); $sth->execute; while ((@data) = $sth->fetchrow_array) { # This is were we grab all the table rows from Sybase and store th +e # an array to be inserted into Sql. push @statement,"INSERT INTO TestClearTransferData(AccountNo,Trans +ferFlag,TransferType,RejectType,AdpNumber,Shares,ProcessingDate) VALU +ES ('$data[0]', '$data[1]', '$data[2]','$data[3]','$data[4]', '$data[ +5]', '$data[6]')"; } #Execute sql statments and if there is an error report it foreach (@statement){ $connection->Sql($_); if ($connection->Error()){ print "\nERROR: \nThe SQL statement:</b>\n $_ \n\n<b>caused th +e error:</b>\n\n ",$connection->Error(); die(); } push @message,$connection->Error(); } #Close the sql DB Connection $connection->Close(); #Close the Sybase DB connection $sth->finish; $dbh2->disconnect;
Edit: Added <code> tags. larsen
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Problem with Code
by Coruscate (Sexton) on Mar 20, 2003 at 20:36 UTC | |
|
Re: Problem with Code
by dga (Hermit) on Mar 20, 2003 at 20:41 UTC | |
by SamueD2 (Novice) on Mar 21, 2003 at 13:39 UTC | |
by dga (Hermit) on Mar 21, 2003 at 15:41 UTC |