THANK YOU!!
I finally maaged by sorting in SQL.
It was not possible to make nested Select.
I could make this better query with left join, but then I couldn't make the filtering work so either I got all records or none...
I could not manage to sort the hash; nothings changed whatever I tried.
BUT
Finally I managed to find out how to write the query.
This was the final (not very nice) working code:
my $query = qq|SELECT
s.shiptofax, s.shiptocountry, s.shiptophone, s.ship
+toaddress1, s.shiptoaddress2,
s.shiptocity, s.shiptostate, s.shiptozipcode,
s.shiptocontact, s.shiptoname, s.shiptoemail, o.waybill, o.s
+hipvia|;
$query .= qq| FROM shipto s, oe o
WHERE ((trans_id = $form->{"$form->{vc}_id"}) AND ( trans_i
+d = $form->{"$form->{vc}_id"})
AND ((to_date( s.shiptophone, 'YYYY-MM-DD') >= to_da
+te( to_char(current_timestamp,'YYYY-MM-DD'), 'YYYY-MM-DD'))
))|;
$query .= qq| UNION
SELECT
s.shiptofax, s.shiptocountry, s.shiptophone, s.shiptoaddre
+ss1, s.shiptoaddress2,
s.shiptocity, s.shiptostate, s.shiptozipcode,
s.shiptocontact, s.shiptoname,
s.shiptoemail, 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_da
+te( to_char(current_timestamp,'YYYY-MM-DD'), 'YYYY-MM-DD'))
))|;
$query .= qq| UNION
SELECT
s.shiptofax, s.shiptocountry, s.shiptophone, s.shiptoaddres
+s1, s.shiptoaddress2,
s.shiptocity, s.shiptostate, s.shiptozipcode,
s.shiptocontact, s.shiptoname,
s.shiptoemail, 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_da
+te( to_char(current_timestamp,'YYYY-MM-DD'), 'YYYY-MM-DD'))
)) |;
if ($form->{id}) {
$query .= qq|
EXCEPT
SELECT
s.shiptofax, s.shiptocountry, s.shiptophone, s.shiptoaddress
+1, s.shiptoaddress2,
s.shiptocity, s.shiptostate, s.shiptozipcode,
s.shiptocontact, s.shiptoname,
s.shiptoemail, o.waybill, o.shipvia
FROM shipto s, oe o
WHERE ((s.trans_id = '$form->{id}') AND ( o.id = '$form->{id}
+'))
|;
}
$query .= qq| ORDER BY shiptofax, shiptostate |;
I should find a way to get rid of all the double records (containing the same information) but thats another question...
Regards/ G! |