sub Query_TotalBatches() { my($Rows, $Prepare_Batch, $RowValue_Batch, $RowValue_Count); my @ColumnsValues = (); $Query_String_Batch = "select left(B.B_num,3) as JD, sum(B.B_COUNT) as Doc_Cnt, P.PROJECTED_VOL as Proj_Vol, P.DATAMARK_RECD as DataMark_Recd, P.JD_CURRENT as JD_Current, P.JD_FUTURE as JD_Future from $TBL_NAME B left join $TBL_PROJVOL P on P.REPORT_IMPORT_DT = B.REPORT_IMPORT_DT where B.REPORT_IMPORT_DT =?group by left(b_num,3)"; $Prepare_Batch = $dbh->prepare($Query_String_Batch); print "1 = $Query_String_Batch\n";; $RowValue_Batch = $Prepare_Batch->execute($ReportDate) || print "Error : ".$dbh->errstr."<\/p>"; $RowsFlag = False; if ( $RowValue_Batch > 0 ) { my $RowCount = 0; while ( $Rows = $Prepare_Batch->fetchrow_hashref ){ $ColumnsValues[0] = $Rows->{JD}; $ColumnsValues[1] = $Rows->{Doc_Cnt}; $ColumnsValues[2] = $Rows->{Proj_Vol}; $ColumnsValues[3] = $Rows->{DataMark_Recd}; $ColumnsValues[4] = $Rows->{JD_Current} if ($RowCount == 0); $ColumnsValues[4] = $Rows->{JD_Future} if ($RowCount == 1); $DailyReport{TB}{$ColumnsValues[0]} = [ @ColumnsValues ]; $DailyReport{TB}{DocCount} += $Rows->{Doc_Cnt} if (length($Rows->{DocCount})>0); $DailyReport{TB}{ProjVolume} += $Rows->{Proj_Vol} if (length($Rows->{DocCount})>0); $DailyReport{TB}{DMIReceived} += $Rows->{DataMark_Recd} if (length($Rows->{DocCount})>0); # $DailyReport{TB}{JDCount} = ($Rows->{JD_Current} + $Rows->{JD_Future}) if (length($Rows->{JD_Current})>0 and length($Rows->{JD_Future})>0); $RowCount++; # Print "1 = @ColumnsValues = $DailyReport{TB}{DocCount} = $DailyReport{TB}{ProjVolume} = $DailyReport{TB}{DMIReceived} = $DailyReport{TB}{JDCount}\n";; } } }