You can try this:
CREATE TABLE #Analysis
(
ID INT IDENTITY,
Margin [numeric](21, 6) NULL,
Gallons INT,
Freight [numeric](21, 6) NULL,
AccMargin [numeric](21, 6) NULL)
INSERT INTO #Analysis ( Margin,Gallons,Freight)
SELECT 0.050220,5022,-30.180000
INSERT INTO #Analysis ( Margin,Gallons,Freight)
SELECT 0.050220,-5022,318.260000
UPDATE #Analysis
SET AccMargin = FLOOR(10000000*(CAST(MArgin AS DECIMAL(22,7))/CAST(Gallons AS DECIMAL(22,7)) +
CAST(Freight AS DECIMAL(22,7))/CAST(Gallons AS DECIMAL(22,7))))/10000000
SELECT * FROM #Analysis
DROP TABLE #Analysis
You might also want to try it without the CASTs but I think they'll be necessary.
My thought question: Have you ever been told that your query runs too fast?
My advice:
INDEXing a poor-performing query is like putting sugar on cat food. Yeah, it probably tastes better but are you sure you want to eat it?
The path of least resistance can be a slippery slope. Take care that fixing your fixes of fixes doesn't snowball and end up costing you more than fixing the root cause would have in the first place.
Need to UNPIVOT? Why not CROSS APPLY VALUES instead?[/url]
Since random numbers are too important to be left to chance, let's generate some![/url]
Learn to understand recursive CTEs by example.[/url]
[url url=http://www.sqlservercentral.com/articles/St