in reply to retrieve data from array empty
I don't have experience with how MySQL behaves, but many other database drivers do not like having more than one statement handle active.
My approach to check this would be to first fetch all rows from your first SQL statement and then loop over them to fetch the rows for the second SQL statement:
my @customers= $dbh->selectall_arrayref(<<SQL, { Slice => {} }); select deb.id from fte_intra.debiteuren deb where deb.type='sms' AND (deb.Afloop_contract='0000-00-00' OR month(deb.Afloop_contract +)='$lastmonth') group by deb.id order by deb.id SQL for my $ref (@customers) { { $invoice_cid = $ref->{'id'}; my $statement = "select mc.cid,mc.mail_month from gmsms.mail_count + mc where mc.cid = '$invoice_cid' AND mc.month='$lastmonth' AND mc.ye +ar='$yearG'"; my $sth = $DBH->prepare($statement); ... };
Personally, I would try to eliminate the two database queries in favour of one SQL statement that combines finding out who is to be billed and the sent bills, potentially something like
select deb.id , mc.cid , mc.mail_month from fte_intra.debiteuren deb left join gmsms.mail_count mc on (mc.cid = deb.id) where deb.type='sms' AND (deb.Afloop_contract='0000-00-00' OR month(deb.Afloop_contract)= +'$lastmonth') AND mc.month='$lastmonth' AND mc.year='$yearG' group by deb.id order by deb.id
That way you offload most of the work onto the database. On the Perl side, you now need to remember the last customer and find out the places in the resultset where a new customer begins.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
| A reply falls below the community's threshold of quality. You may see it by logging in. |