Creo que quieres algo como lo siguiente. La tabla temporal @Output capturará las identidades insertadas para la primera tabla, luego se pueden usar al insertar en la segunda tabla.
DECLARE @Output TABLE
( FirstTableID INT NOT NULL PRIMARY KEY,
WarehouseCode VARCHAR(3),
CustomerCode VARCHAR(4)
)
INSERT INTO FirstTable (WarehouseCode, CustomerCode)
OUTPUT inserted.FirstTblID, inserted.WarehouseCode, inserted.CustomerCode INTO @Output
SELECT DISTINCT LEFT(LocationCode, 3) [WarehouseCode], CustomerCode
FROM [PrimaryTable]
INSERT INTO SecondTable (ItemCode, LocationCode, CustomerCode, FirstTblID)
SELECT p.ItemCode,
p.LocationCode,
p.CustomerCode,
o.FirstTableID
FROM [PrimaryTable] p
INNER JOIN @Output o
ON LEFT(LocationCode, 3) = WarehouseCode
AND p.CustomerCode = o.CustomerCode