SELECT Stocklist.tcsno_ AS 'TCSNO', Stocklist.translocal_, Part.type_ AS '型式', Part.spec_ AS '尺寸',
(SELECT SUM(transqty_) AS Expr1
FROM Stocklist AS a
WHERE (tcsno_ = stocklist.tcsno_) AND (LEFT(transtype_, 1) = 'A') AND (translocal_ = Stocklist.translocal_)) AS '入庫數', ISNULL
((SELECT SUM(transqty_) AS Expr1
FROM Stocklist AS c
WHERE (stocklist.tcsno_ = tcsno_) AND (translocal_ = Stocklist.translocal_) AND (LEFT(transtype_, 1) IN ('B', 'C'))), 0) AS '出庫數', ISNULL
((SELECT SUM(transqty_) AS Expr1
FROM Stocklist AS c
WHERE (stocklist.tcsno_ = tcsno_) AND (LEFT(transtype_, 1) = 'A') AND (translocal_ = Stocklist.translocal_)), 0) - ISNULL
((SELECT SUM(transqty_) AS Expr1
FROM Stocklist AS c
WHERE (stocklist.tcsno_ = tcsno_) AND (translocal_ = Stocklist.translocal_) AND (LEFT(transtype_, 1) IN ('B', 'C'))), 0) AS '當前庫存',
ISNULL
((SELECT SUM(transqty_) AS Expr1
FROM Stocklist AS c
WHERE (stocklist.tcsno_ = tcsno_) AND (transtype_ IN ('CA'))), 0) AS '預庫數', ISNULL
((SELECT TOP (1) translocal_
FROM Stocklist AS c
WHERE (stocklist.tcsno_ = tcsno_) AND (transtype_ IN ('CA'))), 0) AS '預庫架位', ISNULL
((SELECT COUNT(translocal_) AS Expr1
FROM Stocklist AS c
WHERE (stocklist.tcsno_ = tcsno_) AND (transtype_ IN ('CA'))), 0) AS '筆'
FROM Stocklist INNER JOIN
Part ON Stocklist.tcsno_ = Part.partno_
GROUP BY Stocklist.tcsno_, Stocklist.translocal_, Part.type_, Part.spec_
HAVING (ISNULL
((SELECT SUM(transqty_) AS Expr1
FROM Stocklist AS c
WHERE (stocklist.tcsno_ = tcsno_) AND (LEFT(transtype_, 1) = 'A') AND (translocal_ = Stocklist.translocal_)), 0) - ISNULL
((SELECT SUM(transqty_) AS Expr1
FROM Stocklist AS c
WHERE (stocklist.tcsno_ = tcsno_) AND (translocal_ = Stocklist.translocal_) AND (LEFT(transtype_, 1) IN ('B', 'C'))), 0) > 0)
------
這隻難搞的程式,怎一直寫不出來呢 (秀出 庫存2個架位以上的清單,以更讓倉管人員把分散多架位的產品 集中在一個架位)
希望今天下班前 應該能想出語法。 |