This is the SQL-Query:
select my011_LAG_Mandant,my011_LAG_MandantOrdner,my011_LAG_Artikelnummer,my011_LAG_Inventurmenge,
my011_LAG_res19,my011_LAG_Inventurdatum, my011_LAG_Inventurmenge+sum_bewegung_total
from my011_lag_lagerdatei lag
inner join my204_tmpfp_formpos
on my204_TMPFP_Mandant=my011_LAG_Mandant and my204_TMPFP_MandantOrdner=my011_LAG_MandantOrdner and
my204_TMPFP_Artikelnr=my011_LAG_Artikelnummer
join ( select slbp.my022_LBP_ID_Lagerartikel, my022_LBP_Datum, SUM(slbp.my022_LBP_Bewegung) AS sum_bewegung_total
from my022_lbp_lagerbewegungprot slbp
group by slbp.my022_LBP_ID_Lagerartikel
) lbp
on lbp.my022_LBP_ID_Lagerartikel=lag.my011_LAG_ID
Description:
lag (my011_LAG) is the full product table
my204_TMPFP is a subset of pruducts, where users put in only these products, which should calculated, so its a filter
lbp is a table with all stock movements from products
goal is, that << SUM(slbp.my022_LBP_Bewegung) AS sum_bewegung_total >> in JOIN ... should calculate a total sum of stock movements of the linked product. This works fine with the given syntax.
Now comes the problem:
Total sum should calculated only from movements after a specific stocktaking date, which is stored in my011_LAG_Inventurdatum in lag.
So I tried this with a where clause in JOIN:
join ( select slbp.my022_LBP_ID_Lagerartikel, my022_LBP_Datum, SUM(slbp.my022_LBP_Bewegung) AS sum_bewegung_total
from my022_lbp_lagerbewegungprot slbp
where my022_LBP_Datum>lag.my011_LAG_Inventurdatum
group by slbp.my022_LBP_ID_Lagerartikel
) lbp
on lbp.my022_LBP_ID_Lagerartikel=lag.my011_LAG_ID
but this isn't working and I need it solved. It gives the error "lag.my011_LAG_Inventurdatum unknown" whithin the where clause.