i prefer using cte instead of temporary table
; with table1grouped as (
SELECT ItemName,Sum(Quantity) as Quantity
FROM table1
GROUP BY itemName
), table2grouped as (
SELECT ItemName,Sum(Quantity) as Quantity
FROM table2
GROUP BY itemName
)
SELECT ItemName, (t1g.Quantity - ISNULL(t2g.Quantity,0)) as Quantity
FROM table1grouped t1g
LEFT JOIN table2grouped t2g on t1g.ItemName = t2g.ItemName