Subject Re: [IBO] Calculated Fields
Author Laurie McIntosh
In case anyone's been following this, I decided to abandon calculated
fields as being too hard. I've gone back to letting SQL make the
calculation with a CASE statement. Here's what I've finished with:

SELECT S.SAILDOWDESC,
S.DPDESC,
S.SAILINGS,
S.PAX,
S.CARS,
S.TRUCKS,
S.MOTORBIKES,
S.TRAILERS,
S.REVENUE,
CASE WHEN S.SAILINGS = 0 OR S.SAILINGS IS NULL THEN 0
ELSE S.REVENUE / S.SAILINGS END AS A_REV

FROM
(SELECT EXTRACT(WEEKDAY FROM S1.SAILDATE ) AS SAILDOWORD,
DOW(S1.SAILDATE) AS SAILDOWDESC,
T.TERMINUSDESC || ' TO ' || T2.TERMINUSDESC AS DPDESC,
COUNT (S1.SAILDATE) AS SAILINGS,
SUM (S1.PAX) AS PAX,
SUM (S1.CARS) AS CARS,
SUM (S1.TRUCKS) AS TRUCKS,
SUM (S1.MOTORBIKES) AS MOTORBIKES,
SUM (S1.TRAILERS) AS TRAILERS,
SUM (S1.REVENUE) AS REVENUE

FROM TERMINII T, SAILINGDATA S1, TERMINII T2

WHERE T.TERMINUSNO=S1.DEPARTUREPOINT
AND T2.TERMINUSNO=S1.DESTINATION
AND S1.SAILDATE BETWEEN :D1 AND :D2
AND S1.DEPARTUREPOINT = :P
AND S1.DESTINATION = :D
AND S1.VESSEL = :V

GROUP BY 1, 2, 3, T.TERMINUSDESC
ORDER BY 1, T.TERMINUSDESC ) S

Sure wish I'd gotten them calculated fields worked out. It's having a
dog and barking as well as far as I'm concerned.

Regards,

---=L