T
tobyzak99 via AccessMonster.com
Hi
In a stored procedure I am currently updating a table by inserting a
calculation into a temporary table and then updating another table with the
values from the temp table.
Is there a way to update the table in one hit without using the temp table
SELECT CASE SUM(TotalQuantity) WHEN 0 THEN 0 ELSE SUM(TotalCost) / SUM
(TotalQuantity) END AS AveragePrice
Into #TempTable
FROM BudgetTable
GROUP BY BudgetYear, Account
UPDATE OtherTable
SET OtherTable.AveragePrice = #TempTable.AveragePrice
FROM #TempTable
JOIN OtherTable
ON #TempTable.BudgetYear = OtherTable.BudgetYear AND
#TempTable.Account = OtherTable.Account
Thanks - Toby
In a stored procedure I am currently updating a table by inserting a
calculation into a temporary table and then updating another table with the
values from the temp table.
Is there a way to update the table in one hit without using the temp table
SELECT CASE SUM(TotalQuantity) WHEN 0 THEN 0 ELSE SUM(TotalCost) / SUM
(TotalQuantity) END AS AveragePrice
Into #TempTable
FROM BudgetTable
GROUP BY BudgetYear, Account
UPDATE OtherTable
SET OtherTable.AveragePrice = #TempTable.AveragePrice
FROM #TempTable
JOIN OtherTable
ON #TempTable.BudgetYear = OtherTable.BudgetYear AND
#TempTable.Account = OtherTable.Account
Thanks - Toby