增加单据中丢失的商品对应颜色

2017/05/16 14:41:56
/*
特别说明:此脚本只适用于Q7+的版本
*/

--订货单
INSERT INTO InventoryColor(cInvCode,cColorCode)
SELECT DS.cInvCode, DS.cColorCode
FROM OrderDS DS LEFT JOIN InventoryColor IC ON DS.cInvCode = IC.cInvCode AND DS.cColorCode = IC.cColorCode
WHERE IC.cColorCode IS NULL
GROUP BY DS.cInvCode, DS.cColorCode

--采购/生产计划单
INSERT INTO InventoryColor(cInvCode,cColorCode)
SELECT DS.cInvCode, DS.cColorCode
FROM PurchaseDS DS LEFT JOIN InventoryColor IC ON DS.cInvCode = IC.cInvCode AND DS.cColorCode = IC.cColorCode
WHERE IC.cColorCode IS NULL
GROUP BY DS.cInvCode, DS.cColorCode

--库存期初
INSERT INTO InventoryColor(cInvCode,cColorCode)
SELECT DS.cInvCode, DS.cColorCode
FROM StockFirstDS DS LEFT JOIN InventoryColor IC ON DS.cInvCode = IC.cInvCode AND DS.cColorCode = IC.cColorCode
WHERE IC.cColorCode IS NULL
GROUP BY DS.cInvCode, DS.cColorCode

--盘点单
INSERT INTO InventoryColor(cInvCode,cColorCode)
SELECT DS.cInvCode, DS.cColorCode
FROM CheckDS DS LEFT JOIN InventoryColor IC ON DS.cInvCode = IC.cInvCode AND DS.cColorCode = IC.cColorCode
WHERE IC.cColorCode IS NULL
GROUP BY DS.cInvCode, DS.cColorCode

--库存调整单
INSERT INTO InventoryColor(cInvCode,cColorCode)
SELECT DS.cInvCode, DS.cColorCode
FROM ProfitLossDS DS LEFT JOIN InventoryColor IC ON DS.cInvCode = IC.cInvCode AND DS.cColorCode = IC.cColorCode
WHERE IC.cColorCode IS NULL
GROUP BY DS.cInvCode, DS.cColorCode

--采购入库
INSERT INTO InventoryColor(cInvCode,cColorCode)
SELECT DS.cInvCode, DS.cColorCode
FROM ReceiptDS DS LEFT JOIN InventoryColor IC ON DS.cInvCode = IC.cInvCode AND DS.cColorCode = IC.cColorCode
WHERE IC.cColorCode IS NULL
GROUP BY DS.cInvCode, DS.cColorCode

--采购退货单
INSERT INTO InventoryColor(cInvCode,cColorCode)
SELECT DS.cInvCode, DS.cColorCode
FROM VReturnDS DS LEFT JOIN InventoryColor IC ON DS.cInvCode = IC.cInvCode AND DS.cColorCode = IC.cColorCode
WHERE IC.cColorCode IS NULL
GROUP BY DS.cInvCode, DS.cColorCode

--收退货单
INSERT INTO InventoryColor(cInvCode,cColorCode)
SELECT DS.cInvCode, DS.cColorCode
FROM ReturnInDS DS LEFT JOIN InventoryColor IC ON DS.cInvCode = IC.cInvCode AND DS.cColorCode = IC.cColorCode
WHERE IC.cColorCode IS NULL
GROUP BY DS.cInvCode, DS.cColorCode

--仓库调入单
INSERT INTO InventoryColor(cInvCode,cColorCode)
SELECT DS.cInvCode, DS.cColorCode
FROM WMoveInDS DS LEFT JOIN InventoryColor IC ON DS.cInvCode = IC.cInvCode AND DS.cColorCode = IC.cColorCode
WHERE IC.cColorCode IS NULL
GROUP BY DS.cInvCode, DS.cColorCode

--仓库调出单
INSERT INTO InventoryColor(cInvCode,cColorCode)
SELECT DS.cInvCode, DS.cColorCode
FROM WMoveOutDS DS LEFT JOIN InventoryColor IC ON DS.cInvCode = IC.cInvCode AND DS.cColorCode = IC.cColorCode
WHERE IC.cColorCode IS NULL
GROUP BY DS.cInvCode, DS.cColorCode

--配货单
INSERT INTO InventoryColor(cInvCode,cColorCode)
SELECT DS.cInvCode, DS.cColorCode
FROM RationDS DS LEFT JOIN InventoryColor IC ON DS.cInvCode = IC.cInvCode AND DS.cColorCode = IC.cColorCode
WHERE IC.cColorCode IS NULL
GROUP BY DS.cInvCode, DS.cColorCode

--出货单
INSERT INTO InventoryColor(cInvCode,cColorCode)
SELECT DS.cInvCode, DS.cColorCode
FROM DeliveryDS DS LEFT JOIN InventoryColor IC ON DS.cInvCode = IC.cInvCode AND DS.cColorCode = IC.cColorCode
WHERE IC.cColorCode IS NULL
GROUP BY DS.cInvCode, DS.cColorCode

--渠道收货单
INSERT INTO InventoryColor(cInvCode,cColorCode)
SELECT DS.cInvCode, DS.cColorCode
FROM DeliveryInDS DS LEFT JOIN InventoryColor IC ON DS.cInvCode = IC.cInvCode AND DS.cColorCode = IC.cColorCode
WHERE IC.cColorCode IS NULL
GROUP BY DS.cInvCode, DS.cColorCode

--渠道退货单
INSERT INTO InventoryColor(cInvCode,cColorCode)
SELECT DS.cInvCode, DS.cColorCode
FROM DeliveryReturnDS DS LEFT JOIN InventoryColor IC ON DS.cInvCode = IC.cInvCode AND DS.cColorCode = IC.cColorCode
WHERE IC.cColorCode IS NULL
GROUP BY DS.cInvCode, DS.cColorCode

--自营零售单
INSERT INTO InventoryColor(cInvCode,cColorCode)
SELECT DS.cInvCode, DS.cColorCode
FROM RetailCDS DS LEFT JOIN InventoryColor IC ON DS.cInvCode = IC.cInvCode AND DS.cColorCode = IC.cColorCode
WHERE IC.cColorCode IS NULL
GROUP BY DS.cInvCode, DS.cColorCode

--加盟零售单
INSERT INTO InventoryColor(cInvCode,cColorCode)
SELECT DS.cInvCode, DS.cColorCode
FROM RetailLDS DS LEFT JOIN InventoryColor IC ON DS.cInvCode = IC.cInvCode AND DS.cColorCode = IC.cColorCode
WHERE IC.cColorCode IS NULL
GROUP BY DS.cInvCode, DS.cColorCode


--渠道调出通知
INSERT INTO InventoryColor(cInvCode,cColorCode)
SELECT DS.cInvCode, DS.cColorCode
FROM BMoveOutAdviceDS DS LEFT JOIN InventoryColor IC ON DS.cInvCode = IC.cInvCode AND DS.cColorCode = IC.cColorCode
WHERE IC.cColorCode IS NULL
GROUP BY DS.cInvCode, DS.cColorCode

--渠道调出
INSERT INTO InventoryColor(cInvCode,cColorCode)
SELECT DS.cInvCode, DS.cColorCode
FROM BMoveOutDS DS LEFT JOIN InventoryColor IC ON DS.cInvCode = IC.cInvCode AND DS.cColorCode = IC.cColorCode
WHERE IC.cColorCode IS NULL
GROUP BY DS.cInvCode, DS.cColorCode

--渠道退货申请
INSERT INTO InventoryColor(cInvCode,cColorCode)
SELECT DS.cInvCode, DS.cColorCode
FROM ReturnApplyDS DS LEFT JOIN InventoryColor IC ON DS.cInvCode = IC.cInvCode AND DS.cColorCode = IC.cColorCode
WHERE IC.cColorCode IS NULL
GROUP BY DS.cInvCode, DS.cColorCode

--渠道退货审批
INSERT INTO InventoryColor(cInvCode,cColorCode)
SELECT DS.cInvCode, DS.cColorCode
FROM ReturnAdviceDS DS LEFT JOIN InventoryColor IC ON DS.cInvCode = IC.cInvCode AND DS.cColorCode = IC.cColorCode
WHERE IC.cColorCode IS NULL
GROUP BY DS.cInvCode, DS.cColorCode

--仓库调拨通知单
INSERT INTO InventoryColor(cInvCode,cColorCode)
SELECT DS.cInvCode, DS.cColorCode
FROM WMoveOutAdviceDS DS LEFT JOIN InventoryColor IC ON DS.cInvCode = IC.cInvCode AND DS.cColorCode = IC.cColorCode
WHERE IC.cColorCode IS NULL
GROUP BY DS.cInvCode, DS.cColorCode

--采购申请单
INSERT INTO InventoryColor(cInvCode,cColorCode)
SELECT DS.cInvCode, DS.cColorCode
FROM PurchaseApplyDS DS LEFT JOIN InventoryColor IC ON DS.cInvCode = IC.cInvCode AND DS.cColorCode = IC.cColorCode
WHERE IC.cColorCode IS NULL
GROUP BY DS.cInvCode, DS.cColorCode

--代销结算单
INSERT INTO InventoryColor(cInvCode,cColorCode)
SELECT DS.cInvCode, DS.cColorCode
FROM AgentRetailDS DS LEFT JOIN InventoryColor IC ON DS.cInvCode = IC.cInvCode AND DS.cColorCode = IC.cColorCode
WHERE IC.cColorCode IS NULL
GROUP BY DS.cInvCode, DS.cColorCode