====== {$page} ====== ===== Explanation of SQL ===== This query will return the inventory levels and values as of a specific point in history. ===== Risk of Data Corruption if Run Improperly ===== **None**. This is a selection query and no data is modified in the running of it. ===== SQL ===== [[code_formatsql]] DECLARE @HistoricDate DATETIME; SET @HistoricDate = '12/31/09 23:59'; DECLARE @LastUnitCost TABLE(PartID INT PRIMARY KEY, LastInvLogID INT, UnitCost FLOAT); INSERT INTO @LastUnitCost (PartID, LastInvLogID) SELECT IL.PartID, MAX(IL.ID) ID FROM InventoryLog IL LEFT JOIN Journal J ON (J.ID = IL.ID) WHERE (IL.ID > 0) AND (IL.PartID IS NOT NULL) AND (J.StartDateTime