Subject | Re: Subselects |
---|---|
Author | Svein Erling |
Post date | 2004-03-16T14:37:39Z |
> When I've first encountered this, i solved it immediately and thenAre you sure, Bogdan? Helen once told me never to think of parameters
> tested in local database and found out that if iuse field from outer
> select or conditions in subselects - the results aren't predictable
> anymore.
as variables, but as placeholders. Your query in question is
> SELECT VALID_FROM, PRICE FROM MATERIALCENAand here you have two parameters which you have given the same name.
> 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;
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