SELECT s.*, o.waybill, o.shipvia FROM shipto s, oe o WHERE trans_id = $form->{"$form->{vc}_id"} AND to_date(s.shiptophone, 'YYYY-MM-DD') >= to_date(to_char(current_timestamp,'YYYY-MM-DD'), 'YYYY-MM-DD') UNION SELECT s.*, o.waybill, o.shipvia FROM shipto s JOIN oe o ON (o.id = s.trans_id) WHERE o.$form->{vc}_id = $form->{"$form->{vc}_id"} AND to_date(s.shiptophone, 'YYYY-MM-DD') >= to_date(to_char(current_timestamp,'YYYY-MM-DD'), 'YYYY-MM-DD') UNION SELECT s.*, a.waybill, a.shipvia FROM shipto s JOIN $table a ON (a.id = s.trans_id) WHERE a.$form->{vc}_id = $form->{"$form->{vc}_id"} AND to_date(s.shiptophone, 'YYYY-MM-DD') >= to_date(to_char(current_timestamp,'YYYY-MM-DD'), 'YYYY-MM-DD')