I have a SELECT statement that uses the result of a function multiple times. Instead of repetitively tapping the function, is there a way that I can assign a variable to it in order to make the statement more efficient and I don't have to keep tapping the function?
Overly Simplified Hypothetical Example Code:
DECLARE @Total Decimal(18,2)
SELECT t.ClientName AS Customer, t.ClientID,
--This function returns total sales for the Client
@Total = dbo.functionSalesTotal(t.ClientID),
@Total AS Sales, (@Total * 0.13) AS Tax,
(@Total + (@Total *0.13)) AS TotalIncludingTax
FROM table t