# The main Select $sth_main = $dbh->prepare(<<'__EOSQL__'); SELECT DISTINCT t.account_no, t.telephony_id, n.sim, n.mobile_number, s.user_name, s.contract_status, s.dealer, to_char(t.eff_start_date,'DD.MM.YYYY'), to_char(s.signed_date,'DD.MM.YYYY'), to_char(s.subscr_change_upd,'DD.MM.YYYY'), lpad(s.s_id,7,'0'), to_char(t.eff_start_date,'HH24:MI:SS') FROM new_sim n, subscription s, tele_period t WHERE (t.account_no = n.account_no) AND (t.telephony_id = n.mobile_number) AND (t.account_no = s.account_no) AND (t.telephony_id = s.mobile_number) ORDER BY t.account_no, t.telephony_id __EOSQL__