Products Not sold or Purchased Since Date (SQL)
v6,v7
Finds Products not sold or purchased since date
SELECT PM."Ref_Number", PM."Name", PM."Class", PM."Buy_Size", pm."Sell_Price_w_Tax", PM."Complex",
(select max(GLL1."Trn_Date") from "General_Ledger_Log" GLL1 where GLL1."Prd_Num" = PM."Ref_Number" and GLL1."Trn_Source" = 'D') as "Last_Sold",
(select max(GLL2."Trn_Date") from "General_Ledger_Log" GLL2 where GLL2."Prd_Num" = PM."Ref_Number" and GLL2."Trn_Source" = 'C' and GLL2."Inv_Type" <> 4) as "Last_Purchased"
from "Product_Main" PM
where PM."Ref_Number" > 10000001000
and PM."Class" in ('R', 'D', 'M')
and PM."Status" ='A'
and PM."Complex" in (0,2)
and not exists (select * from "General_Ledger_Log" GLL
where GLL."Prd_Num" = PM."Ref_Number"
and GLL."Trn_Date" >= :Date/*Date*/
and (GLL."Trn_Source" = 'C' or GLL."Trn_Source" = 'D')
and GLL."Inv_Type" <> 4)
Order by "Ref_Number"