in reply to Code flow not going to while loop
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; }
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: Code flow not going to while loop
by dipit (Sexton) on Aug 02, 2017 at 18:18 UTC | |
by poj (Abbot) on Aug 02, 2017 at 18:51 UTC |