INSERT INTO ActualAmountsByLocation (ItemBarcode, Location, LocationName, Amount, isCustomerItem, LastUpdate)
SELECT * FROM (
SELECT DISTINCT m.ItemBarcode,m.ToLocationType+m.ToNo AS Location,l.shortdesc AS LocationName, dbo.spGetActualAmountByLocation(m.ItemBarcode,m.ToLocationType+m.ToNo) AS Amount, 0 AS isCustomerItem,
GETDATE() AS LastUpdate FROM dbo.StockMovement m, RefLocations l WHERE m.ToLocationType='L' AND m.ToLocationType+m.ToNo=l.code AND m.ItemBarcode=@Barcode AND m.TransactionType=1
) a ORDER BY ItemBarcode,Location
UPDATE ActualAmountsByLocation SET isCustomerItem=1 WHERE ItemBarcode IN (SELECT barcode FROM StockMaterials WHERE barcode=@Barcode AND ownership=1)
UPDATE ActualAmountsByLocation SET isCustomerItem=1 WHERE ItemBarcode IN (SELECT barcode FROM StockTools WHERE barcode=@Barcode AND ownership=1)
UPDATE ActualAmountsByLocation SET isCustomerItem=1 WHERE ItemBarcode IN (SELECT barcode FROM StockComponents WHERE barcode=@Barcode AND ownership=1)
SET @ReturnMsg = RTRIM(@ReturnMsg) + 'E25: Transaction completed successfully ' + CHAR(13) + CHAR(10) |