I appreciate your response and help. Does this help? The problem starts with the while loop.
############################ # # Set the Perl Modules # ############################ use strict; use DBI; use Spreadsheet::WriteExcel::Big; use Mail::Sender; my $i = 0; my $j = 1;..... ############################### # # Create Array_ref for array. # ############################### my $rows = $query->fetchall_arrayref; ############################### # # Load ID data in array for indexing. # Note: The initial fetching of the array loads into array index 0. ############################### foreach $i(0..$#{$rows}) { foreach $j (0..$#{$rows->[$i]} ) { $rows->[$i][$j]; } }################################################################### # # Wrap the process into a loop to iterate through the array by index. # ################################################################### while ($i<=2) { my $placeholder = ":p_$j"; print "$placeholder\n"; my $rd = "$rows->[$i][0]"; print "$rd\n"; # create a new EXCEL instance my $Excelfile = "Q4 $rd PERFORMANCE RPT.xls"; my $excel = Spreadsheet::WriteExcel::Big->new("$Excelfile"); my $worksheet = $excel->addworksheet("Q4_STORE"); ###Create Subroutine to Select Data and insert into Worksheet### sub get_store_data { # Connect to Oracle database. # Set up Query for Specific ID. my $stmt = "select week_end_date, SVP, RD, DM, store, wtd_smrr_gain,QTD_SMRR_GAIN, wtd_bor_gain,QTD_BOR_GAIN, wtd_cust_gain,QTD_CUST_GAIN, WTD_CARD_CLOSED,QTD_AVG_CARD_CL from bonus_4Q_store where SVP <> 'RD' and RD = ? order by svp,dm,store"; # Prepare Query my $sth = $dbh->prepare($stmt); # Bind Parameters. #$sth->bind_param($placeholder, $rd); # Execute Query $sth->execute($rd) or die $dbh->errstr;L); # Create an array reference. my $a_row = $sth->fetchall_arrayref(); # insert Data into spreadsheet foreach $stmt (@{$a_row}) {$worksheet->write_col(14,0,$a_row,$format); last;} # Finish part 1 $sth->finish(); $dbh->rollback; $dbh->disconnect(); }###end of function1### # Call Functions / Subroutines &get_store_data; print "$rd DONE WITH Q4 Store DATA! \n"; $excel->close(); #execute email.... $i++; $j++; } exit(0);
In reply to Re^2: SQL query using dynamic array
by cocl04
in thread SQL query using dynamic array
by cocl04
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |