Hi Experts,
I have 2 queries which I need to combine the fields, the 1st query will display all document and last purchase price of an item per document date range, while the 2nd one will display the Vendor Cost history (this is Price List 01) tagged to an item depending also on the update date range. Will it be possible to combine these queries wherein all “0” values will come from each other queries.
In my final output, I want to display the following:
- top 1(first) PriceBefDi if there are multiple records for a specific document date range
- last purchase price based on the document date range
- orginal vendor cost or price list 01 during the AP invoice was created
- current vedor cost or price list 01 for the specific date range.
Is this possible. I will appreciate any help.
SELECT 'PurchasePrice'AS [PriceType],
T1.DocDate,
T0.ItemCode,
T0.Dscription,
T2.ItmsGrpCod,
T3.ItmsGrpNam,
T0.PriceBefDi as [Document Purchase Price],
T2.LastPurPrc as [Last Purchase Price],
0 as [Average Purchase Price],
0 as [Original Vendor Cost],
0 as [Current Vendor Cost],
T0.Quantity
FROM dbo.PCH1 T0
INNERJOIN dbo.OPCH T1 ON T0.DocEntry = T1.DocEntry
INNERJOIN dbo.OITM T2 ON T0.ItemCode = T2.ItemCode
INNERJOIN dbo.OITB T3 ON T2.ItmsGrpCod = T3.ItmsGrpCod
Where T1.DocDate >='2014-10-01'and T1.DocDate <='214-11-17'
SELECT 'VendorCost'AS [PriceType],
T0.UpdateDate,
T0.ItemCode,
T3.ItemName,
T3.ItmsGrpCod,
T4.ItmsGrpNam,
0 as [Document Purchase Price],
0 as [Last Purchase Price],
0 as [Average Purchase Price],
T1.Price as [Original Vendor Cost],
T2.price as [Current Vendor Cost],
0 as'Quantity'
FROM AITM T0
Join AIT1 T1 On T0.LogInstanc=T1.LogInstanc
and T0.ItemCode=T1.ItemCode AND T1.PriceList = 1
innerjoin ITM1 T2 on T0.ItemCode = T2.ItemCode and T2.PriceList =1
innerjoin OITM T3 on T0.ItemCode = T3.ItemCode
innerjoin OITB T4 on T3.ItmsGrpCod = T4.ItmsGrpCod
WHERE T1.PriceList ='1'
And T0.updatedate >='2014-10-01'and T0.updatedate <='2014-11-17'
Thanks,
Maria