# your original queries format odd so I adjusted it slightly # think this may also be the source of your results # being duplicated my $sth = $dbh->prepare_cached(qq!SELECT DISTINCT A.p_code, A.business, A.status, A.value, A.login, A.enc_date, B.name, B.state FROM business A, users B WHERE A.login = ? AND A.data_enc_proposta = ? ORDER BY A.login, A.data_enc_proposta!); } $dbh = SysUtils::Connect; # $login_value and $data_enc_value have to come # from somewhere. $sth->execute($login_value,$data_enc_value); while (my ($rs,$neg,$st,$vp,$gel,$dte,$gen,$fil) = $sth->fetchrow_array()) { my $hashref = { $fil => { $gel => { $dte => { cliente => "$rs", negocio => "$neg", status => "$st", valor => "$vp", nome => "$gen" } } } } ); ListaDados($hashref); } #### sub ListDados { my ($dados) = @_; foreach (keys %{$dados}) { $vf = "R\$ "; $tf = "R\$ "; $dados->{$fil}{$gel}{$dte}{valor} =~ s/\.0000$/\,00/; $vf .= $dados->{$fil}{$gel}{$dte}{valor}; if ($cnt eq 0) { $message .= qq! $dados->{$fil}{$gel}{$dte}{nome} !; $cnt++; ($color2,$color1) = ($color1,$color2); } else { $message .= qq!!; ($color2,$color1) = ($color1,$color2); } } }
Client Business Status Value

$dados->{$fil}{$gel}{$dte}{cliente} $dados->{$fil}{$gel}{$dte}{negocio} $dados->{$fil}{$gel}{$dte}{status} $vf
$dados->{$fil}{$gel}{$dte}{cliente} $dados->{$fil}{$gel}{$dte}{negocio} $dados->{$fil}{$gel}{$dte}{status} $vf