2017-08-23 85 views
0

中的表的列結構中的SQL多個表如下:加入用於庫存維護應用程序

tbl_PIVD = pivID | prodID | Qty | ScaleID 
tbl_GRN = gID | pivID 
tbl_GRND = grndID | gID | prodID | Qty | ScaleID 
tbl_prod = prodID | ScaleID(SIunit) 

問題:獲得的數量(數量)和它的未決差=

ConvertScale(tbl_PIVD.Qty, tbl_PIVD.ScaleID, tbl_prodID.ScaleID) - 
ConvertScale(tbl_GRND.Qty, tbl_GRND.ScaleID, tbl_prodID.ScaleID) 

tbl_PIVDtbl_GRND表,其中tbl_PIVD.pivID = tbl_GRN.pivIDtbl_PIVD.prodID = tbl_GRND.prodID

減法是使兩個規模相等,規模使用功能ConvertScale

如何加入以下查詢

SELECT PID.Qty, GRND.Qty FROM tbl_PIVD PID INNER 
JOIN tbl_GRND GRND on 
PID.prodId = GRND.prodId 


SELECT * FROM tbl_PIVD PID INNER JOIN 
tbl_GRN GRN ON PID.pivId = GRN.pivID 
GRN.pivID=10609 

回答

0

我希望下面的查詢將有用的轉換後進行。

SELECT ConvertScale(PD.Qty, PD.ScaleID, P.ScaleID) - 
ConvertScale(GD.Qty, GD.ScaleID, P.ScaleID) as 'PendingQty' 
FROM tbl_PIVD PD 
INNER JOIN tbl_Prod P ON PD.ProdID = P.ProdID 
INNER JOIN tbl_GRN G ON PD.pivID = G.pivID 
INNER JOIN tbl_GRND GD ON G.gID = GD.gID AND PD.prodID = GD.prodID