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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.