I wrote a SELECT statment for a report but it uses the CASE statment a lot and each time it is checking for the same value. Is there a way I can optimize this a bit more?SELECT t.Terminal_Name AS Location, di.ProductName + ' (' + di.ProductNumber + ')' AS Product, null AS 'Total Tank Capacity', Begging = CASE WHEN t.Gross_Gallons_Terminal = 'Y' THEN di.StartingGrossInv ELSE di.STartingNetInv END, Receipts = CASE WHEN t.Gross_Gallons_Terminal = 'Y' THEN r.Gross ELSE r.Net END, Adjustments = CASE WHEN t.Gross_Gallons_Terminal = 'Y' THEN a.Gross ELSE a.Net END, Sales = CASE WHEN t.Gross_Gallons_Terminal = 'Y' THEN s.Gross ELSE s.Net END, Ending = CASE WHEN t.Gross_Gallons_Terminal = 'Y' THEN di.EndingGrossInv ELSE di.EndingNetInv END, Type = CASE WHEN t.Gross_Gallons_Terminal = 'Y' THEN 'Gross' ELSE 'Net' END, tp.Temp, tp.Gravity, null AS 'End < Capacity', 'End < 0' = CASE WHEN t.Gross_Gallons_Terminal = 'Y' AND di.EndingGrossINV > 0 THEN 'OK' WHEN t.Gross_Gallons_Terminal <> 'Y' AND di.EndingNetInv > 0 THEN 'OK' ELSE '***ERROR***' END
-- If I get used to envying others...Those things about my self I pride will slowly fade away.-Stellvia