Quote:
| Originally Posted by paulpitchford Could you elaborate on this? |
it's a true pity that microsoft access does such a
shïtty job of formatting sql, not only running everything into one long continuous line, but tossing (all those (useless (ridiculous))) parentheses all over da place
let's first just simply reformat your query --
Code:
SELECT tst_Paul_UnionJoinOrdersDels.OrderNo
, tst_Paul_FilmIssued.[SumOfQty Issued]
, tst_Paul_FilmDeliveries.SumOfDeldQtyKilos
, tst_Paul_FilmReturns.[SumOfQty Issued]
FROM ((
tst_Paul_UnionJoinOrdersDels
LEFT
JOIN tst_Paul_FilmIssued
ON tst_Paul_UnionJoinOrdersDels.OrderNo = tst_Paul_FilmIssued.[Order No From]
)
LEFT
JOIN tst_Paul_FilmDeliveries
ON tst_Paul_UnionJoinOrdersDels.OrderNo = tst_Paul_FilmDeliveries.OrderNo
)
LEFT
JOIN tst_Paul_FilmReturns
ON tst_Paul_UnionJoinOrdersDels.OrderNo = tst_Paul_FilmReturns.[Order No From]
WHERE (((tst_Paul_FilmIssued.[SumOfQty Issued])>=0))
OR (((tst_Paul_FilmDeliveries.SumOfDeldQtyKilos)>=0))
OR (((tst_Paul_FilmReturns.[SumOfQty Issued])>=0));
now it's easier to see the conditions after they've been moved to the ON clauses --
Code:
SELECT tst_Paul_UnionJoinOrdersDels.OrderNo
, tst_Paul_FilmIssued.[SumOfQty Issued]
, tst_Paul_FilmDeliveries.SumOfDeldQtyKilos
, tst_Paul_FilmReturns.[SumOfQty Issued]
FROM ((
tst_Paul_UnionJoinOrdersDels
LEFT
JOIN tst_Paul_FilmIssued
ON tst_Paul_UnionJoinOrdersDels.OrderNo = tst_Paul_FilmIssued.[Order No From]
AND (((tst_Paul_FilmIssued.[SumOfQty Issued])>=0))
)
LEFT
JOIN tst_Paul_FilmDeliveries
ON tst_Paul_UnionJoinOrdersDels.OrderNo = tst_Paul_FilmDeliveries.OrderNo
AND (((tst_Paul_FilmDeliveries.SumOfDeldQtyKilos)>=0))
)
LEFT
JOIN tst_Paul_FilmReturns
ON tst_Paul_UnionJoinOrdersDels.OrderNo = tst_Paul_FilmReturns.[Order No From]
AND (((tst_Paul_FilmReturns.[SumOfQty Issued])>=0))
sadly, access is gonna bitch about the AND in the ON clauses ("join expression not supported" or similar), so here we are forced to add more parentheses
as a last step, i like to use table aliases ( thus reducing the total number of characters of code, making the forest easier to see amongst all the trees), as well as removing unnecessary parentheses and switching the join columns in the ON clause
Code:
SELECT o.OrderNo
, i.[SumOfQty Issued]
, d.SumOfDeldQtyKilos
, r.[SumOfQty Issued]
FROM ((
tst_Paul_UnionJoinOrdersDels AS o
LEFT
JOIN tst_Paul_FilmIssued AS i
ON ( i.[Order No From] = o.OrderNo
AND i.[SumOfQty Issued] >= 0 )
)
LEFT
JOIN tst_Paul_FilmDeliveries AS d
ON ( d.OrderNo = o.OrderNo
AND d.SumOfDeldQtyKilos >=0 )
)
LEFT
JOIN tst_Paul_FilmReturns AS r
ON ( r.[Order No From] = o.OrderNo
AND r.[SumOfQty Issued] >=0 )
helps?