Quote:
|
Originally Posted by Peter.Vanroose
Try this:
Code:
SELECT <whatever> FROM <wherever>
WHERE chdate = (SELECT MAX(chdate) FROM <wherever>
WHERE chdate <= &AAAAMMGG)
Only in the case when there would be no chdate before &AAAAMMGG, no rows will be shown. In all other cases, all rows with the most recent date not later than &AAAAMMGG will be shown. (The "FETCH FIRST ROW ONLY" solution will just pick one amongst those.)
|
Excuse me, Peter, I'm trying to apply your formula to my query
with nested tables but I can't find the right commands:
SELECT ......
FROM
( SELECT * FROM TABLE1
WHERE ISCODE = 785
AND &DATE BETWEEN SECISS AND SECMAT
) as a
LEFT OUTER JOIN TABLE 2 AS C
ON ( (DATEB < &DATE AND DEND > &DATE) )
LEFT OUTER JOIN TABLE3 AS D
ON ((MAX(CHDATE) WHERE CHDATE <= &DATE) )
) as aaa) as bbb) as ccc) AS DDD) AS EEE) AS FFF) AS GGG) AS HHH
Thank you.
Anna - Verona (Italy)