on 2024 Aug 06 3:01 PM
Hello,
I'm trying to create a report for the change in quantity made on a BoM.
SELECT
T0.Code,
T1.Code,
T1.Quantity 'Current Qty',
T2.Quantity 'Old Qty',
T1.LogInstanc,
T2.LogInstanc,
T0.UpdateDate,
T3.USER_CODE 'Updated By'
FROM OITT T0
INNER JOIN ITT1 T1 ON T0.Code = T1.Father
INNER JOIN ATT1 T2 ON T2.Code = T1.Code
INNER JOIN OUSR T3 ON T3.USERID = T0.UserSign2
WHERE
T0.Code = '10596860'AND
DATEDIFF(DD,T0.UpdateDate, GETDATE()) <=1
AND T1.Quantity <> T2.Quantity
This report gives me multiple lines (I can see based on the T2.loginstance) and I would like to see only the latest change to the quantity made.
Also, how to get the details of components added or removed from the ITT1 Table?
Any assistance would be appreciated.
Regards,
Joseph
Hi Joseph,
please try this
DECLARE @Father AS NVARCHAR(max) = '10596860'
SELECT
T1.Father,
T1.Code,
T1.Quantity 'Current Qty',
T0.UpdateDate,
T3.USER_CODE 'Updated By',
Hist.*
FROM
OITT T0
INNER JOIN ITT1 T1 ON T0.Code = T1.Father
OUTER APPLY
(SELECT
Father
,Code
,Quantity
,LogInstanc
FROM ATT1
WHERE LogInstanc = (
SELECT
Max(T99.LogInstanc)
FROM ATT1 T99
WHERE
T99.Quantity <> T1.Quantity AND T99.Code = T1.Code AND T99.Father = T1.Father AND T99.ChildNum = T1.ChildNum
)
AND Code = T1.Code AND Father = T1.Father AND ChildNum = T1.ChildNum) Hist
INNER JOIN OUSR T3 ON T3.USERID = T0.UserSign2
WHERE
T1.Father = @Father
AND
DATEDIFF(DD,T0.UpdateDate, GETDATE()) <=1
AND T1.Quantity <> Hist.Quantity
regards Lothar
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
93 | |
10 | |
8 | |
6 | |
6 | |
5 | |
5 | |
5 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.