Insert into Table2(stock_name,temple,quantity)
SELECt a.stock_name, a.temple, SUM(Case when Type=’purchase’ then quantity else (quantity*-1) End) AS quantity
FROM Table1 a
GROUP BY a.stock_name, a.temple

Insert into Table2(stock_name,temple,quantity)
SELECt a.stock_name, a.temple, SUM(Case when Type=’purchase’ then quantity else (quantity*-1) End) AS quantity
FROM Table1 a
GROUP BY a.stock_name, a.temple