Consider replacing the hash of start/end dates with YEAR(date) and MONTH(date)functions.
poj#!/usr/bin/perl use DBI; use strict; my $sql =<< "SQL"; SELECT distinct FID_CUST FROM session WHERE YEAR(DAT_END) = ? AND MONTH(DAT_END) = ? SQL my $dbh = get_dbh(); my $sth = $dbh->prepare($sql); my $year = 2017; for my $mth (1..9) { print "$year-$mth\n"; $sth->execute($year,$mth); while (my ($fid_cust)= $sth->fetchrow_array ){ print "$fid_cust\n"; } $sth->finish(); } $dbh->disconnect; # connect sub get_dbh{ my $database = "xxx"; my $user = "xxx"; my $pw = "xxx"; my $dsn = "dbi:DB2:$database"; my $dbh = DBI->connect($dsn, $user, $pw, { RaiseError=>1, AutoCommit=>1 } ) or die "Could not connect to database :".DBI->errstr; return $dbh; }
In reply to Re: Code flow not going to while loop
by poj
in thread Code flow not going to while loop
by dipit
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |