IF COL_LENGTH('dbo.Tw_InputDetailBarCode', 'Quantity') IS NULL
BEGIN
    ALTER TABLE dbo.Tw_InputDetailBarCode
        ADD Quantity DECIMAL(18, 4) NULL;
END;
GO

-- 历史非管材条码每个代表1件；按米计量的管材数量由扫码业务录入，保持为空。
UPDATE barCode
SET barCode.Quantity = 1
FROM dbo.Tw_InputDetailBarCode AS barCode
LEFT JOIN dbo.HJGL_MaterialCodeLib AS material
    ON material.MaterialCode = barCode.MaterialCode
WHERE barCode.Quantity IS NULL
  AND ISNULL(LTRIM(RTRIM(material.MaterialUnit)), N'') <> N'米';
GO
