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", "User", "Pass", {RaiseError => 1, PrintError => 1, AutoCommit => 1} ) or die "Unable to connect: ";#. $DBI::errstr . "\n"; # Sybase Connection my $dbh2 = DBI->connect( "dbi:ODBC:BPSA", "User", "Pass", {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.tacat_trnfr.branch_cd + dbo.tacat_t +rnfr.acct_cd) As AccountNo,case when (dbo.tacat_trnfr.dlvr_nbr= '0044 +') then 'RCV_NBR' when (dbo.tacat_trnfr.rcv_nbr = '0044')then 'DLVR _ +NBR' end As ContraFirmNo, case when (dbo.tacat_trnfr.trnfr_type_cd = 'FUL' or dbo.tacat_trnfr. +trnfr_type_cd = 'PTD')then 'ACT' when (dbo.tacat_trnfr.trnfr_type_cd += ' PTR') then 'PCT' end as TransferType, case when (dbo.tacat_trnfr.dlvr_nbr= '0044') then 'DLR' when (dbo.taca +t_trnfr.rcv_nbr = '0044')then 'TRI'end As TransferFlag, case when (dbo.tacat_trnfr.stts_cd = '140') then 'S' when (dbo.tacat_t +rnfr.stts_cd = '300'or dbo.tacat_trnfr.stts_cd = '310') then 'C' when + (dbo.tacat_trnfr.stts_cd = '400' or dbo.tacat_trnfr.stts_cd = '500' +or dbo.tacat_trnfr.stts_cd = '600') then 'H'end as RejectType, dbo.tacat_trnfr.cmnt_txt as Comment FROM dbo.tacat_trnfr WHERE dbo.tacat_trnfr.stts_cd in ('140','300','310','400','500','600') +"); $sth->execute; my $insh=$dbh->prepare("INSERT INTO TestClearTransferData(AccountNo,Co +ntraFirmNo,TransferType,RejectType,Comment) VALUES ( ?,?,?,?,?)"); eval { while((@data) = $sth->fetchrow_array) { $insh->execute(@data); } }; if($@) { print STDERR "The insert died: $@"; } #Close the sql DB Connection $dbh->disconnect; #Close the Sybase DB connection $sth->finish; $dbh2->disconnect;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Problem with case in select statement
by zby (Vicar) on Mar 21, 2003 at 15:42 UTC | |
by SamueD2 (Novice) on Mar 21, 2003 at 16:55 UTC | |
by dws (Chancellor) on Mar 21, 2003 at 19:43 UTC | |
by zby (Vicar) on Mar 21, 2003 at 18:19 UTC | |
|
Re: Problem with case in select statement
by iburrell (Chaplain) on Mar 21, 2003 at 17:23 UTC | |
|
Re: Problem with case in select statement
by dws (Chancellor) on Mar 31, 2003 at 18:04 UTC | |
|
Re: Problem with case in select statement
by mpeppler (Vicar) on Mar 31, 2003 at 17:58 UTC |