on 06-25-2015 1:54 AM
Hello All
I am trying to write a query that will display any components that isn't in any BOM's or Open production Orders
The query should only display Item codes that belong to the ItemGroupCode = 287 and should display item codes which are on hand
I have written the below, but doesn't work
Hoping someone can point me or guide me in the right direction
SELECT T0.[ItemCode],
T0.[ItemName],
T0.[OnHand],
(T0.[OnHand] * T0.[AvgPrice]) as 'Value Of Stock'
FROM OITM T0 INNER JOIN ITT1 T1 ON T0.ItemCode = T1.Code INNER JOIN WOR1 T2 ON T0.ItemCode = T2.ItemCode
WHERE T0.[ItemCode] not in T1.[Code] and T2.[ItemCode] and T0.[ItmsGrpCod] = 287 and T0.[OnHand] >= 1
ORDER BY T0.[ItemName]
Thanks and Regards
Rahul
Dear Rahul,
Please try below query
--------------
;WITH BOM_PDN AS
(Select A.Code [Item_Code]
from ITT1 A
Group By A.Code
Union
Select B.ItemCode [Item_Code]
from WOR1 B
Inner Join OWOR C on B.DocEntry = C.DocEntry
Where C.Status in ('P','R')
Group By B.ItemCode
)
SELECT T0.[ItemCode],
T0.[ItemName],
T0.[OnHand],
(T0.[OnHand] * T0.[AvgPrice]) as 'Value Of Stock'
FROM OITM T0
WHERE T0.[ItemCode] not in (Select T1.Item_Code from BOM_PDN T1)
and T0.[ItmsGrpCod] = 287
and T0.[OnHand] >= 1
ORDER BY T0.[ItemName]
----------------
Thanks
Unnikrishnan
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Rahul,
that is not two separate queries.
You have to run together.
First part is Common table expression (CTE) creating a temporary table and store some values in that table.
Second part is another query, which we are taking taking data from both SAP tables and Temp table.
Please run it together and reply
All the best
Unnikrishnan
Hi Rahul,
Please try this
----------
;WITH BOM_PDN AS
(Select A.Code [Item_Code]
from ITT1 A
Group By A.Code
Union
Select B.ItemCode [Item_Code]
from WOR1 B
Inner Join OWOR C on B.DocEntry = C.DocEntry
Where C.Status in ('P','R')
Group By B.ItemCode
)
SELECT T0.[ItemCode],
T0.[ItemName],
T0.[OnHand],
(T0.[OnHand] * T0.[AvgPrice]) as 'Value Of Stock'
FROM OITM T0
WHERE T0.[ItemCode] not in (Select T1.Item_Code from BOM_PDN T1)
and T0.[ItmsGrpCod] = 287
and T0.[OnHand] >= 1
and T0.ItemCode Not like '%PW%'
ORDER BY T0.[ItemName]
------
Thanks
Unnikrishnan
User | Count |
---|---|
107 | |
12 | |
10 | |
5 | |
5 | |
3 | |
3 | |
3 | |
3 | |
2 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.