Hello!
Im trying edit this sql to show the refill amount of an product. Hope anyone can help or give some guidance.
For example
- There are an order for 7 iphones
- The pick location in the warehouse only has 5 iphones on location
- So I want one more filed in the sql that shows "refill 2"
(order amount) | (stock balance) | (new field wanted) | |||
---|---|---|---|---|---|
partno | partdsc1 | Kollinummer | BeställtAntal | balpl | refill |
123 | Iphone | 176601714 | 7 | 5 | 2 |
I guess that I should add something like this, but I cant figure out how to get it to work
CAST(SUM("_Beställt" - balpl) AS FLOAT) AS "_Påfyllnad"
;With TMP AS
(Select G.partno,SUM(amooncr) '_Antal på Buffert', L.partdsc1, balpl, pmha
FROM ASTRO_VIEW_CNT_G08T1 AS G
JOIN L62T1 AS L
ON G.partno=L.partno
Where wmha LIKE 'FBROD'
Group by G.partno, balpl, pmha, L.partdsc1),
TMP2 AS
(Select O.partno, CONVERT (INT,ROUND(SUM(reqquant),0)) AS '_BeställtAntal', TMP.partdsc1, balpl, pmha
FROM ASTRO_VIEW_CNT_O08R08 AS O
INNER JOIN TMP
ON O.partno = TMP.partno
Where CAST(oppdate AS DATE) LIKE LEFT(CAST(GETDATE()AS DATE), 10) AND (linestat =2 OR linestat =22) AND routeno NOT LIKE '9%'
Group by O.partno, balpl, pmha, TMP.partdsc1),
TMP3 AS
(Select TMP2.partno, TMP2.partdsc1, MAX(G.ecarrno) AS '_Kollinummer', TMP2._BeställtAntal, balpl, pmha
FROM ASTRO_VIEW_CNT_G08T1 AS G
JOIN TMP2
ON G.partno = TMP2.partno
JOIN
(select ecarrno, mha, rack, horcoor, vercoor, amooncr
FROM ASTRO_VIEW_CNT_G08T1) AS SUB
ON G.ecarrno=SUB.ecarrno
Where G.mha LIKE 'FBROD%' AND carrstat !=8
Group by TMP2.partno, TMP2.partdsc1, TMP2._BeställtAntal, balpl, pmha)
Select TMP3.*, mha, rack, horcoor, vercoor, amooncr
FROM TMP3
INNER JOIN ASTRO_VIEW_CNT_G08T1 AS G
ON TMP3._Kollinummer = G.ecarrno
Order by pmha