Subject Re: Subselects
Author Svein Erling
> When I've first encountered this, i solved it immediately and then
> tested in local database and found out that if iuse field from outer
> select or conditions in subselects - the results aren't predictable
> anymore.

Are you sure, Bogdan? Helen once told me never to think of parameters
as variables, but as placeholders. Your query in question is

> SELECT VALID_FROM, PRICE FROM MATERIALCENA
> WHERE MATERIALid = :IMATERIALID AND VALID_FROM =
> (select max(MC.VALID_FROM from materialcena mc where mc.materialid =
> :imaterialid and mc.VALID_FROM <= 'today')
> INTO :VALID_FROM, :PRICE;

and here you have two parameters which you have given the same name.
I'd say that you should change your select to either

SELECT M.VALID_FROM, M.PRICE FROM M.MATERIALCENA
WHERE M.MATERIALid = :IMATERIALID AND M.VALID_FROM =
(select max(MC.VALID_FROM from materialcena mc where mc.materialid =
:othername and mc.VALID_FROM <= 'today')
INTO :VALID_FROM, :PRICE;

or

SELECT M.VALID_FROM, M.PRICE FROM MATERIALCENA M
WHERE M.MATERIALid = :IMATERIALID AND M.VALID_FROM =
(select max(MC.VALID_FROM from materialcena mc where mc.materialid =
m.materialid and mc.VALID_FROM <= 'today')
INTO :VALID_FROM, :PRICE;

HTH,
Set