|
|
|
|
use qingdao_lafeipairui
|
|
|
|
|
|
|
|
|
|
--<EFBFBD><EFBFBD><EFBFBD>Ʋ<EFBFBD>Ʒ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>λ
|
|
|
|
|
DELETE TGoodsMultiUnit WHERE FUnitType = 1
|
|
|
|
|
INSERT INTO TGoodsMultiUnit(FId,FGoodsId,FUnitType,FUnitId,FSequence,FConvDir,FConvRate,FSalePrice,FPurCostPrice,FSaleCostPrice,FConsCostPrice,FBarCode,FUnitLock)
|
|
|
|
|
SELECT dbo.FNNewId(),A.FId AS FGoodsId,1,FUnitId,0,1,1,FSalePrice,FPurCostPrice,FSaleCostPrice,FConsCostPrice,FBarCode,FUnitLock
|
|
|
|
|
FROM TGoods AS A
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
--<EFBFBD><EFBFBD>λ<EFBFBD><EFBFBD>
|
|
|
|
|
UPDATE A
|
|
|
|
|
SET A.FUnitLock = 1
|
|
|
|
|
FROM TGoods AS A,TInventoryHist AS B
|
|
|
|
|
WHERE A.FId = B.FGoodsId
|
|
|
|
|
|
|
|
|
|
UPDATE A
|
|
|
|
|
SET A.FUnitLock = 1
|
|
|
|
|
FROM TGoodsMultiUnit AS A,TInventoryHist AS B
|
|
|
|
|
WHERE A.FGoodsId = B.FGoodsId
|
|
|
|
|
AND A.FUnitType = 1
|
|
|
|
|
|
|
|
|
|
UPDATE A
|
|
|
|
|
SET A.FUnitLock = 1
|
|
|
|
|
FROM TGoodsMultiUnit AS A,TInventoryHist AS B
|
|
|
|
|
WHERE A.FGoodsId = B.FGoodsId
|
|
|
|
|
AND A.FUnitId = B.FUnitId
|
|
|
|
|
AND A.FUnitType != 1
|
|
|
|
|
|
|
|
|
|
use jinan_gt
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
--<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʷ<EFBFBD>Ϳ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
SELECT * FROM
|
|
|
|
|
(
|
|
|
|
|
|
|
|
|
|
SELECT G.FNo,G.FName,C.FNo AS CompNo,A.FBatchNo, A.FGoodsId,A.FCompId,A.FStoreId,A.FQuantity,B.FHistQuantity
|
|
|
|
|
|
|
|
|
|
FROM (
|
|
|
|
|
SELECT A.FGoodsId,A.FCompId,A.FStoreId,SUM(A.FQuantity) AS FQuantity,A.FBatchNo
|
|
|
|
|
FROM TInventory AS A
|
|
|
|
|
GROUP BY A.FGoodsId,A.FCompId,A.FStoreId ,A.FBatchNo
|
|
|
|
|
) AS A
|
|
|
|
|
,
|
|
|
|
|
(
|
|
|
|
|
SELECT A.FGoodsId,A.FCompId,A.FStoreId,A.FBatchNo, SUM(A.FInStdQuantity) - SUM(A.FOutStdQuantity) AS FHistQuantity
|
|
|
|
|
FROM TInventoryHist AS A
|
|
|
|
|
GROUP BY A.FGoodsId,A.FCompId,A.FStoreId ,A.FBatchNo
|
|
|
|
|
) AS B, TGoods AS G,TCompany AS C
|
|
|
|
|
WHERE G.FId = A.FGoodsId
|
|
|
|
|
AND G.FId = B.FGoodsId
|
|
|
|
|
AND A.FGoodsId = B.FGoodsId
|
|
|
|
|
AND A.FStoreId = B.FStoreId
|
|
|
|
|
AND A.FCompId = B.FCompId
|
|
|
|
|
AND A.FCompId = C.FId
|
|
|
|
|
AND A.FBatchNo = B.FBatchNo
|
|
|
|
|
) AS A
|
|
|
|
|
WHERE A.FQuantity != A.FHistQuantity
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
--<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
UPDATE A
|
|
|
|
|
SET A.FQuantity = B.FHistQuantity
|
|
|
|
|
FROM TInventory AS A, (
|
|
|
|
|
SELECT A.FGoodsId,A.FCompId,A.FStoreId,A.FBatchNo,SUM(A.FInStdQuantity) - SUM(A.FOutStdQuantity) AS FHistQuantity
|
|
|
|
|
FROM TInventoryHist AS A
|
|
|
|
|
GROUP BY A.FGoodsId,A.FCompId,A.FStoreId ,A.FBatchNo
|
|
|
|
|
) AS B
|
|
|
|
|
WHERE A.FCompId = B.FCompId
|
|
|
|
|
AND A.FGoodsId = B.FGoodsId
|
|
|
|
|
AND A.FStoreId = B.FStoreId
|
|
|
|
|
AND A.FBatchNo = B.FBatchNo
|
|
|
|
|
AND A.FQuantity != B.FHistQuantity
|
|
|
|
|
--<EFBFBD>ĵ<EFBFBD>λ
|
|
|
|
|
|
|
|
|
|
DECLARE @GoodsId BIGINT
|
|
|
|
|
DECLARE @NewUnitId BIGINT
|
|
|
|
|
DECLARE @OldUnitId BIGINT
|
|
|
|
|
|
|
|
|
|
SELECT @GoodsId = 5254077160902154974
|
|
|
|
|
SELECT @NewUnitId = 7222064295725136969
|
|
|
|
|
SELECT @OldUnitId = 7662466434053986928
|
|
|
|
|
|
|
|
|
|
UPDATE TGoods
|
|
|
|
|
SET FUnitId = @NewUnitId WHERE FId = @GoodsId AND FUnitId = @OldUnitId
|
|
|
|
|
|
|
|
|
|
UPDATE TGoodsMultiUnit
|
|
|
|
|
SET FUnitId = @NewUnitId
|
|
|
|
|
WHERE FGoodsId = @GoodsId
|
|
|
|
|
AND FUnitId = @OldUnitId
|
|
|
|
|
|
|
|
|
|
UPDATE TInventoryLog
|
|
|
|
|
SET FUnitId = @NewUnitId
|
|
|
|
|
WHERE FGoodsId = @GoodsId
|
|
|
|
|
AND FUnitId = @OldUnitId
|
|
|
|
|
|
|
|
|
|
UPDATE A
|
|
|
|
|
SET A.FUnitId = @NewUnitId
|
|
|
|
|
FROM TStockInDetail AS A
|
|
|
|
|
WHERE A.FGoodsId = @GoodsId
|
|
|
|
|
AND A.FUnitId = @OldUnitId
|
|
|
|
|
|
|
|
|
|
UPDATE A
|
|
|
|
|
SET A.FUnitId = @NewUnitId
|
|
|
|
|
FROM TStockOutDetail AS A
|
|
|
|
|
WHERE A.FGoodsId = @GoodsId
|
|
|
|
|
AND A.FUnitId = @OldUnitId
|
|
|
|
|
|
|
|
|
|
UPDATE A
|
|
|
|
|
SET A.FUnitId = @NewUnitId
|
|
|
|
|
FROM TConsumeGoods AS A
|
|
|
|
|
WHERE A.FGoodsId = @GoodsId
|
|
|
|
|
AND A.FUnitId = @OldUnitId
|
|
|
|
|
|